#include <iostream>
#include <string>
#include<math.h>
using namespace std;
int main()
{
int n,R;
while (cin >> n>>R)
{
int i = 0;
int r[100];
for (int a = abs(n); a != 0; i++)
{
r[i] = a%R;
a = a / R;
}
if (n < 0)
cout << '-';
for (int j = i-1; j >= 0; j--)
{
if (r[j] >= 10)
cout << char('A' + r[j] - 10);
else cout << r[j];
}
cout << endl;
}
return 0;
}
#include <string>
#include<math.h>
using namespace std;
int main()
{
int n,R;
while (cin >> n>>R)
{
int i = 0;
int r[100];
for (int a = abs(n); a != 0; i++)
{
r[i] = a%R;
a = a / R;
}
if (n < 0)
cout << '-';
for (int j = i-1; j >= 0; j--)
{
if (r[j] >= 10)
cout << char('A' + r[j] - 10);
else cout << r[j];
}
cout << endl;
}
return 0;
}