#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int n,b;
	string res, table = "0123456789ABCDEF";
	cin >> n >> b;
    if(n == 0) {
        cout<<"0";
        return 0;
    }
	int flag = 1;
	if (n < 0) {
		flag -= 2;
		n *= -1;
	}
	while (n != 0) {
		res += table[n%b];
		n /= b;
	}
    if(flag == -1) res += "-";
    reverse(res.begin(),res.end());
    cout << res;
	return 0;
}