#include <bits/stdc++.h>
using namespace std;
string dic="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
int n,bit,t=0;
bool started=false;
cin >> n >>bit;
for(int i=((int)pow(n,1.0/(double)bit))+1;n!=0;i--) {
while(n>=pow(bit,i)) {
n-=pow(bit,i);
t++;
}
if(t>0)started=true;
if(started)cout << dic[t];
t=0;
}
return 0;
}