/*
5. 输入一个十进数,将其转换成 N 进制数(0<N<=16)。
*/
#include "iostream"
using namespace std;
#define MAX_SIZE 17
int main()
{
const char map[MAX_SIZE] = "0123456789ABCDEF";
int n, N;
char dataBuf[1001+1];
int len = 0;
cin >> n >> N;
int m = n;
while(m / N)
{
dataBuf[len++] = map[m%N];
m /= N;
}
dataBuf[len] = map[m%N];
for(int i=len; i>=0; i--)
{
cout << dataBuf[i];
}
cout << endl;
return 0;
}