#include <iostream>
#include <string>

using namespace std;

// M进制和N进制可能会用到字符
int charToInt(char ch){
    if(ch>='0'&&ch<='9')
        return ch-'0';
    else
        return ch-'A'+10;
}

char intToChar(int in){
    if(in<10)
        return in+'0';
    else
        return in+'A'-10;
}

long long M2D(string str, int m){
    long long number = 0;
    for(int i=0;i<str.length();i++){
        number = number * m + charToInt(str[i]);
    }
    return number;
}

string D2N(long long number, int n){
    string str="";
    while(number!=0){
        str += intToChar(number%n);
        number /= n;
    }
    return str;
}


int main(){
    int m, n;
    while(cin >> m >> n){
        string str;
        cin >> str;
        long long number = M2D(str,m);	//先从M进制转换为10进制
        string res = D2N(number, n);	//再从10进制转换为N进制
        string res_reverse(res.rbegin(),res.rend());	//最后逆序输出
        cout << res_reverse << endl;
    }
    return 0;
}