#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define x first
#define y second
#define int long long
#ifndef LOCAL
const string name = "gfact";
ifstream in(name+".in");
ofstream out(name+".out");
#define cin in
#define cout out
#endif // FIO
const int INF = 1e18+6;
int p,q;
vector<pii> primes;
bool ok(int nr)
{
for(auto e:primes)
{
int cnt=0, me=e.x;
while(me<=nr)
{
cnt+=nr/me;
me*=e.x;
}
if(cnt<e.y*q) return 0;
}
return 1;
}
int32_t main()
{
cin>>p>>q;
int a=p;
int i=2;
while(i*i<=a)
{
int j=0;
while(a%i==0)
{
j++;
a/=i;
}
if(j>0)
{
primes.push_back({i,j});
}
i++;
//cout<<"here "<<i<<' '<<a<<'\n';
}
if(a>0)
{
primes.push_back({a,1});
}
int st=0,dr=INF;
int mid=(st+dr)/2;
while(st!=dr)
{
if(ok(mid))dr=mid;
else st=mid+1;
mid=(st+dr)/2;
}
cout<<mid<<'\n';
return 0;
}