#include<iostream>
#define ll long long
using namespace std;
/* n为输入的10进制数 m为其他进制*/
void valueTrans(ll n,ll m){
ll r=n%m;
if(n>=m)
valueTrans(n/m,m);
if(r<10)
putchar(r+'0');
else
putchar(r-10+'A');
}
int main(){
ll n,m;
while(cin>>n>>m){
valueTrans(n,m);
cout<<endl;
}
return 0;
}