#include
using namespace std;
typedef long long ll;
int main()
{
string mode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string ans;
ll a, b;
cin>>a>>b;
ll ta = a;
while(a)
{
if(a % b >= 0)
{
ans = mode[a % b] + ans;
a /= b;
}
else
{
ans = mode[a - (a / b + 1) * b] + ans;
a = a / b + 1;
}
}
cout<