#include<iostream>
#include<string>
using namespace std;
int pow(int x,int y){ //求x的y次方
int i,s=1;
if(y==0){
return 1;
}
for(i=0;i<y;i++){
s*=x;
}
return s;
}
int main(){
int t=1; int n,r;string ans;
while(cin>>n>>r){
int i=0;ans="";
if(n<0)
{
t=0;n=-n;}
while(n>pow(r,i)){//
i++;
}
i=i-1;
int s;
while(i>=0){
s=n/pow(r,i);
n=n%pow(r,i);
if(s>=10){
if(s==10)
ans+='A';
if(s==11)
ans+='B';
if(s==12)
ans+='C';
if(s==13)
ans+='D';
if(s==14)
ans+='E';
if(s==15)
ans+='F';
}
else
ans+=('0'+s);i--;
}if(t==0)
cout<<"-"<<ans<<endl;
else
cout<<ans<<endl;
t=1;
}
return 0;
}