#include <iostream>
#include <stack>
using namespace std;
int n, k;
stack<int> S;
int main() {
cin >> n >> k;
char str[20] = "0123456789ABCDEF";
while(n>0) {
S.push(n%k);
n = n / k;
}
while(!S.empty()) {
cout << str[S.top()];
S.pop();
}
return 0;
}
ex) n = 5, k = 2