#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,b,n = 0;
cin >> a >> b;
string s;
cin >> s;
string c;
for(int i = 0;i <s.size();i++)
{
if(s[i] >= 'a')
n = n * a+ s[i] - 'a' + 10;
else
n = n * a + s[i] - '0';
}
while(n != 0)
{
if(n % b >= 10)
c = char(n % b - 10 + 'a') + c;
else
c = char(n % b + '0') + c;
n /= b;
}
cout << c;
return 0;
}