#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <math.h>
using namespace std;
#define N 110
int a[N];
int main()
{
int n, m;
while (cin >> n >> m)
{
int f = 1;
if (n < 0) //负数标记
{
n = -n;
f = 0;
}
int i = 0;
while (n > 0)
{
a[i++] = n%m;
n /= m;
}
if (!f) cout << "-";
for (int j=i-1; j >= 0; j--)
{
if (a[j] < 10) cout << a[j];
else
cout << (char)('A' + (a[j] - 10));
}
cout << endl;
}
}
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <math.h>
using namespace std;
#define N 110
int a[N];
int main()
{
int n, m;
while (cin >> n >> m)
{
int f = 1;
if (n < 0) //负数标记
{
n = -n;
f = 0;
}
int i = 0;
while (n > 0)
{
a[i++] = n%m;
n /= m;
}
if (!f) cout << "-";
for (int j=i-1; j >= 0; j--)
{
if (a[j] < 10) cout << a[j];
else
cout << (char)('A' + (a[j] - 10));
}
cout << endl;
}
}