#include<bits/stdc++.h>
using namespace std;
int n,m,c;
char a[21]={'A','B','C','D','E','F','G','\0'};
stack<char> s; 
int main(){
   cin>>n>>m;
   while(n>0){
   	if(n%m<=9)s.push(n%m);
    else s.push(a[n%m-10]);
    n/=m;
    c++;
   }
   if(s.pop()==s.empty())cout<<0;
   for(int i=1;i<=c;i++){
   	int tops=s.top();
   	char topp=s.top();
   	if(topp>='A'&&topp<='Z')cout<<topp;
   	else cout<<tops;
   	s.pop();
   }
   return 0;
}

/**************************************************************
	Problem: 1415
	User: chenjingqi
	Language: C++
	Result: Compile Error
****************************************************************/