#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,c;
   char a[21]={'A','B','C','D','E','F','G','0'};
     stack<char>s; 
   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.empty()==true)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: huxuanchen
	Language: C++
	Result: Runtime Error
****************************************************************/