#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int charToInt(char c){
    if(c>='0'&&c<='9'){
        return c-'0';
    }else{
        return c-'A'+10;
    }
}

long long ConvertToTen(string str,int m){//将M进制转为十进制
    long long number=0,p=1;
    for(int i = str.size()-1;i>=0;i--){
        number = number + charToInt(str[i])*p;
      p = p*m;
    }
    return number;
}

char IntToChar(int x){
    if(x>=0&&x<=9){
        return '0'+x;
    }else{
        return x-10+'A';
    }
}
void ConvertToN(long long num,int N){//除留余数法,将十进制转为N进制
    vector<char> ans;
    do{
        ans.push_back(IntToChar(num%N));
        num = num/N;
    }while(num!=0);
    for(int i = ans.size()-1;i>=0;i--){
        printf("%c",ans[i]);
    }
    printf("\n");
}

int main(){
    int M,N;

    while(scanf("%d%d",&M,&N)!=EOF){
        string str;
        cin >> str;
        long long num = ConvertToTen(str,M);
        ConvertToN(num,N);
        return 0;
    }
    return 0;
}