#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cmath>
using namespace std;
int main() {
//freopen("input.txt", "rt", stdin);
long long n;
long long b;
cin >> n >> b;
stack<long long> s;
while (n>0) {
long long tmp = n % b;
s.push(tmp);
n = n / b;
}
int num = s.size();
for (int i = 0; i < num; i++) {
if (s.top() >= 10) {
printf("%c", s.top() + 'A' - 10);
}
else {
cout << s.top();
}
s.pop();
}
return 0;
}