#include <bits/stdc++.h>
using namespace std;
string t[] = {"I", "V", "X", "L", "C", "D", "M"};
int main(void) {
  int a, b, i;
  string s, B;
  cin >> a >> B >> s;
  long long x = 0;
  for ((i) = 0; (i) < (int)(s.length()); (i)++) {
    x *= a;
    char ch = s[i];
    x += ((ch >= '0' && ch <= '9') ? (ch - '0') : (ch - 'A' + 10));
  }
  if (B == "R") {
    string ans;
    for ((i) = 0; (i) < (int)(4); (i)++) {
      int d = x % 10;
      string tmp;
      if (d == 1) tmp = t[i * 2];
      if (d == 2) tmp = t[i * 2] + t[i * 2];
      if (d == 3) tmp = t[i * 2] + t[i * 2] + t[i * 2];
      if (d == 4) tmp = t[i * 2] + t[i * 2 + 1];
      if (d == 5) tmp = t[i * 2 + 1];
      if (d == 6) tmp = t[i * 2 + 1] + t[i * 2];
      if (d == 7) tmp = t[i * 2 + 1] + t[i * 2] + t[i * 2];
      if (d == 8) tmp = t[i * 2 + 1] + t[i * 2] + t[i * 2] + t[i * 2];
      if (d == 9) tmp = t[i * 2] + t[i * 2 + 2];
      ans = tmp + ans;
      x /= 10;
    }
    cout << ans << endl;
  } else {
    string ans;
    b = atoi(B.c_str());
    while (x > 0) {
      int d = x % b;
      char ch = ((d >= 0 && d <= 9) ? ('0' + d) : ('A' + (d - 10)));
      ans = ch + ans;
      x /= b;
    }
    if (ans.empty()) ans = "0";
    cout << ans << endl;
  }
  return 0;
}
