#include <algorithm>
#include <asm-generic/errno.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    int a, b;
    string mod = "0123456789ABCDEF";
    bool flag = false;
    while (cin >> a >> b) { // 注意 while 处理多个 case
        string s;
        if(a < 0){
            flag = true;
            a = -a;
        }
        if (a == 0) {
            cout << "0" << endl;
            continue;
        } else {
            while (a) {
                s += mod[a % b];
                a = a / b;
            }
            reverse(s.begin(), s.end());
        }
        if(flag)
            cout << "-" << s.c_str() << endl;
        else
            cout << s.c_str() << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")