#include<iostream>
#include<string>
using namespace std;
int n2Dec( int n, string s)
{
int a = 0;
for(int i = 0; i < s.size(); i++)
{
int b = s[i] < 'A' ? s[i] - '0' : s[i] - 'A' + 10;
a = b + a * n;
}
return a;
}
string dec2N(int a, int n)
{
string s;
for(int i = 0; a > 0; i++)
{
int b = a % n;
a /= n;
string str;
str += (b < 10) ? b + '0' : b - 10 + 'A';
s = str + s;
}
return s;
}
int main()
{
int n1;
cin >> n1;
string nStr;
cin >> nStr;
int n2;
cin >> n2;
cout << dec2N(n2Dec(n1, nStr), n2) << endl;
return 0;
}