#include <cstdio>
using namespace std;
FILE *in,*out;
const int L = 60;
const int n = 2000000000;
long long exp(long long x,int baza)
{
long long rez = 0;
while(x > 0)
{
rez += x/baza;
x /= baza;
}
return rez;
}
long long cauta(long long x,int baza)
{
long long pas = 1LL<<L,r = 0;
while(pas > 0)
{
if(r + pas < n && exp(r + pas,baza) < x)
r += pas;
pas /= 2;
}
return r+1;
}
int main()
{
in = fopen("gfact.in","r");
out = fopen("gfact.out","w");
int p,q;
fscanf(in,"%d %d",&p,&q);
int d = 2,cp;
long long r,maxim = -99;
cp = p;
while(d * d <= cp)
{
int putere = 0;
while(cp % d == 0)
{
putere ++;
cp /= d;
}
r = cauta(putere*q,d);
if(r > maxim) maxim = r;
d++;
}
if(cp > 1)
r = cauta(q,cp);
if(r > maxim) maxim = r;
fprintf(out,"%lld",r);
return 0;
}