#include <bits/stdc++.h>
using namespace std;
string rim[] = {"I",  "IV", "V",  "IX", "X",  "XL", "L",
                "XC", "C",  "CD", "D",  "CM", "M"};
int vals[] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
int main() {
  int a, b = 0;
  cin >> a;
  string s, tt;
  cin >> tt;
  if (tt[0] != 'R') {
    for (int i = 0; i < tt.size(); i++) b = b * 10 + (tt[i] - '0');
  } else
    b = 'R';
  cin >> s;
  long long c = 0;
  for (int i = 0, l = s.size() - 1; i < s.size(); i++, l--) {
    long long t = 1;
    if (s[l] - '0' != 0)
      for (int j = 0; j < i; j++) t *= a;
    int ch = s[l] - '0';
    if (ch > 9) ch -= ('A' - '9' - 1);
    c += t * (ch);
  }
  if (b != 'R') {
    string ans;
    for (;;) {
      int v = c % b;
      if (v > 9) {
        v -= 10;
        v += 'A';
      } else
        v += '0';
      ans.push_back(v);
      c /= b;
      if (!c) break;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
  } else {
    while (c)
      for (int i = 12; i >= 0; i--)
        if (c >= vals[i]) {
          cout << rim[i];
          c -= vals[i];
          break;
        }
  }
  return 0;
}
