//十进制转成m进制
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define maxn 20010
using namespace std;
int n,m,l;
char s[10000];
int main()
{
cin>>n>>m;
while(n>0)
{
if(m>10&&n%m>=10)
{
s[l++]=n%m+'A'-10;
}
else
{
s[l++]=n%m+'0';
}
n/=m;
}
for(int i=l-1;i>=0;i--)
{
cout<<s[i];
}
cout<<endl;
return 0;
}
//m进制转成十进制
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define maxn 20010
using namespace std;
char s[10000],*a;
int m;
int main()
{
cin>>s>>m;
cout<<strtol(s,&a,m)<<endl;
return 0;
}