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

int main()
{
    int N,R;
    string a("0123456789ABCDEFG");
    while (cin >> N >> R)
    {
        string s="";
        bool flag = true;
        if (N<0)
        {
            flag = false;
            N = -N;
        }
            
        while (N > 0)
        {
            s = a[N%R] + s;
            N /= R;
        }
        if (!flag)
        {
            s = "-" + s;
        }
        cout << s << endl;
    }
}