#include <iostream>
#include <fstream>
using namespace std;
struct desc
{
int factor,putere;
};
desc a[100];
int y=1;
long long putere(long long n, int p)
{
//returneaza puterea la care apare p in descompunerea lui n!
long long nr=0;
while (n >= p)
{
nr += n/p;
n /= p;
}
return nr;
}
bool sepoate(long long n)
{
for (int i = 1; i <= y; i++)
if (putere(n, a[i].factor) < a[i].putere)
return false;
return true;
}
int main()
{
ifstream in("gfact.in");
ofstream out("gfact.out");
long long m, pas;
int p,q,b,d=2;
in>>p>>q;
b=p;
while(b>1)
{
a[y].putere=0;
while(b%d==0)
{
a[y].putere++;
b=b/d;
}
if(a[y].putere!=0)
{
a[y].putere=a[y].putere*q;
a[y].factor=d;
y++;
}
d=d+1;
}
y--;
m = 0;
pas = 1LL << 20;
while (pas != 0)
{
if (!sepoate(m + pas))
m += pas;
pas /= 2;
}
++m;
out<<m;
return 0;
}