#include <bits/stdc++.h>
using namespace std;
const char radix[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
                      '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                      'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                      'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
const string R_M[] = {"", "M", "MM", "MMM"};
const string R_C[] = {"",  "C",  "CC",  "CCC",  "CD",
                      "D", "DC", "DCC", "DCCC", "CM"};
const string R_X[] = {"",  "X",  "XX",  "XXX",  "XL",
                      "L", "LX", "LXX", "LXXX", "XC"};
const string R_I[] = {"",  "I",  "II",  "III",  "IV",
                      "V", "VI", "VII", "VIII", "IX"};
int main() {
  string b, c;
  int a;
  cin >> a >> b >> c;
  long long int digit = 0;
  for (int i = 0, size = c.size(); i < size; ++i) {
    long long int tmp;
    if (isdigit(c[i]))
      tmp = c[i] - '0';
    else
      tmp = c[i] - 'A' + 10;
    long long int b = 1;
    for (int j = 0; j < size - 1 - i; ++j) b *= a;
    b *= tmp;
    digit += b;
  }
  string ans = "";
  if (b != "R") {
    int r = atoi(b.c_str());
    while (digit != 0) {
      ans = radix[digit % r] + ans;
      digit /= r;
    }
  } else {
    int M = digit / 1000;
    digit %= 1000;
    int C = digit / 100;
    digit %= 100;
    int X = digit / 10;
    int I = digit % 10;
    ans = R_M[M] + R_C[C] + R_X[X] + R_I[I];
  }
  if (ans == "") ans = "0";
  cout << ans << endl;
  return 0;
}
