#include <bits/stdc++.h>
using namespace std;
long long convertfrom(string c, int a) {
  long long s = 0;
  int ch;
  for (int i = 0; i < c.length(); i += 1) {
    ch = c[i];
    if (ch <= 57) {
      s *= a;
      s += ch - 48;
    } else {
      s *= a;
      s += ch - 55;
    }
  }
  return (s);
}
string convertto(long long c, int b) {
  if (c == 0) {
    return "0";
  }
  string s = "";
  int ch;
  while (c > 0) {
    ch = c % b;
    if (ch <= 9) {
      s = (char)(ch + 48) + s;
    } else {
      s = (char)(ch + 55) + s;
    }
    c /= b;
  }
  return s;
}
int main() {
  string roman[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
  string roman2[] = {"",  "X",  "XX",  "XXX",  "XL",
                     "L", "LX", "LXX", "LXXX", "XC"};
  string roman3[] = {"",  "C",  "CC",  "CCC",  "CD",
                     "D", "DC", "DCC", "DCCC", "CM"};
  string roman4[] = {"", "M", "MM", "MMM"};
  int a;
  string b;
  string c;
  cin >> a;
  cin >> b;
  cin >> c;
  if (b[0] == 'R') {
    int cc = convertfrom(c, a);
    string ans = "";
    ans = roman[cc % 10] + ans;
    cc /= 10;
    ans = roman2[cc % 10] + ans;
    cc /= 10;
    ans = roman3[cc % 10] + ans;
    cc /= 10;
    cout << roman4[cc % 10] + ans;
  } else {
    int bb;
    stringstream num(b);
    num >> bb;
    long long cc = convertfrom(c, a);
    cout << convertto(cc, bb);
  }
}
