#include <iostream>
using namespace std;
int main()
{
int n, r, i = 0;
char Lu[100];
while (cin >> n >> r)
{
if (n < 0)
{
cout << "-";
n = -n;
}
while (n > 0)
{
int Yi = n%r;
if (Yi > 9)
Lu[i] = Yi - 10 + 'A';
else
Lu[i] = Yi + '0';
i++;
n = n/r;
}
int j = i;
while (j--)
cout << Lu[j];
cout << endl;
i = 0;
}
return 0;
}