#include <iostream>
#include <string>
#include<vector>
#include <algorithm>
using namespace std;
int a,b;
string n;
vector<int>v;
char ch[16] ={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};



int main() {
    
    cin>>a>>n>>b;
    while(n[0]==0)n.erase(0,1);
    long long cnt = 0;
    for(int i=0;i<n.size();i++)
    {
        if(n[i]>='0'&&n[i]<='9')v.push_back(n[i]-'0');
        else if(n[i]>='a'&&n[i]<='z')v.push_back(n[i]-'a'+10);
        else v.push_back(n[i]-'A'+10);
    }
    reverse(v.begin(),v.end());
    int pow =1;
    for(int i = 0;i<v.size();i++)
    {
        cnt +=v[i]*pow;
        pow *=a;
    }
    v.clear();
    if(cnt==0)cout<<0<<endl;
    while(cnt!=0)
    {
        v.push_back(cnt%b);
        cnt /=b;
    }
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<ch[v[i]];
    }
    cout<<endl;

}
// 64 位输出请用 printf("%lld")