#include<bits/stdc++.h>
using namespace std;
char jz[20]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
int main(){
long long x,m,y;
int a[100],k=0;
cin>>x>>m;
while(x!=0){
a[++k]=x%m;
x/=m;
}
for(int i=k;i>=1;i--){
cout<<jz[a[i]];
}
return 0;
}