#include<iostream>
using namespace std;
int main()
{
long n = 0; //待转换的数字
int x = 0; //进制
int a = 0; //转换后的单位字符
int m = 0; //转换后的位数
int s[100]; //转换后字符串
cin >> n >> x;
while (n!=0)
{
a=n%x;
n=n/x;
m++;
s[m]=a;
}
for(int i = m; i >= 1; i--)
{
if(s[i]>=10)
//大于等于10,默认使用字母表示
cout << (char)(s[i] + (65 - 10)) << endl;
else
cout << s[i] << endl;
}
return 0;
}