#include <bits/stdc++.h>
using namespace std;
long long a, b;
char sir[1005];
long long nr10;
long long converteste() {
  long long ans = 0;
  long long putere = 1;
  for (int i = strlen(sir) - 1; i >= 0; i--) {
    if (sir[i] <= '9')
      ans += (putere * (sir[i] - '0'));
    else
      ans += (putere * (sir[i] - 'A' + 10));
    putere *= a;
  }
  return ans;
}
int main() {
  string x;
  cin >> a >> x >> sir;
  if (x[0] == 'R')
    b = 'R';
  else if (x.size() > 1)
    b = x[1] - '0' + (x[0] - '0') * 10;
  else
    b = x[0] - '0';
  if (b == 'R') {
    nr10 = converteste();
    if (nr10 / 1000 > 0)
      for (int i = 1; i <= nr10 / 1000; i++) cout << 'M';
    string lista[] = {"0", "C",  "CC",  "CCC",  "CD",
                      "D", "DC", "DCC", "DCCC", "CM"};
    if ((nr10 % 1000 / 100) != 0) cout << lista[(nr10 % 1000 / 100)];
    string lista2[] = {"0", "X",  "XX",  "XXX",  "XL",
                       "L", "LX", "LXX", "LXXX", "XC"};
    if ((nr10 % 100 / 10)) cout << lista2[(nr10 % 100 / 10)];
    string lista3[] = {"0", "I",  "II",  "III",  "IV",
                       "V", "VI", "VII", "VIII", "IX"};
    if (nr10 % 10) cout << lista3[nr10 % 10];
  } else {
    nr10 = converteste();
    string ans = "";
    while (nr10 > 0) {
      long long r = nr10 % b;
      char lit;
      if (r >= 10)
        lit = 'A' + r - 10;
      else
        lit = r + '0';
      ans = lit + ans;
      nr10 /= b;
    }
    cout << ans;
    if (ans.size() == 0) cout << 0;
  }
  return 0;
}
