#include <iostream>
using namespace std;

int m, n;
string s;

int main() {
    while(cin >> m >> n)
    {
        cin >> s;
        long long num = 0;
        char res[100];
        int i = 0, k;

        for(int i = 0; i < s.size(); i++)
            if(s[i] >= 'A' && s[i] <= 'Z')
                num = num * m + s[i] - 'A' + 10;
            else 
                num = num * m + s[i] - '0';
        //cout << num << endl;
        while(num)
        {
            k = num % n;
            num /= n;
            if(k >= 10) res[i++] = k - 10 + 'a';
            else res[i++] = k + '0';
        }

        for(int j = i - 1; j >= 0; j--)
            cout << res[j];
        cout << endl;
        
    }
}