//m转n进制可先由 m转十 在由十转n
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
char int2char(int target) {
if (target <=9) {//<=
return target + '0';
}
else {
return target - 10 + 'A';
}
}
void convert(long long number, int n) {
vector<char> vec;
if (number == 0) {
vec.push_back(0);
}
else {
while (number != 0) {
vec.push_back(int2char(number % n));
number /= n;
}
}
for (int i = vec.size() - 1; i >= 0; i--) {
printf("%c", vec[i]);
}
printf("\n");
}
int char2int(char c) {
if (c <= '9') {
return c - '0';
}
else {
return c - 'A' + 10;
}
}
long long convertmtt(string str, int m) {
long long number = 0;
for (int i = 0; i < str.size(); i++) {
number *= m;
number += char2int(str[i]);
}
return number;
}
int main() {
int m, n;
while (scanf("%d%d", &m, &n) != EOF) {
string str;
cin >> str;
long long number = convertmtt(str, m);// m zhuan shi
convert(number, n);// shi zhuan n
}
return 0;
}