#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
unsigned long long n10,nb,b,rest,poz=1,v1001,maxi=0;
int main()
{
cin>>n10>>b;
while(n10>0)
{
rest=n10%b;
n10=n10/b;
nb=nb+rest*poz;
poz*=10;
}int i=1;
while(nb)
{v[i]=nb%10;
nb/=10;i++;}
for(int x=1;x<=i;x++)
if(v[x]>maxi)
maxi=v[x];
cout<<maxi;
}