#include <bits/stdc++.h>
using namespace std;
void rec(long long x, long long y) {
  if (x == 0) return;
  rec(x / y, y);
  long long z = x % y;
  if (z >= 10)
    cout << (char)(z + 55);
  else
    cout << z;
}
int main() {
  string b, c;
  long long q, a, d = 0, i, j, s = 0, l;
  cin >> a >> b >> c;
  l = c.length();
  for (j = 1, i = l - 1; i >= 0; i--) {
    if (c[i] > 63)
      s += (j * (c[i] - 55));
    else
      s += (j * (c[i] - 48));
    j *= a;
  }
  if (b[0] == 'R') {
    for (; s >= 1000; s -= 1000) cout << "M";
    if (s / 100 == 9) {
      cout << "CM";
      s %= 100;
    }
    if (s >= 500) {
      cout << "D";
      s -= 500;
    }
    if (s / 100 == 4) {
      cout << "CD";
      s %= 100;
    }
    for (; s >= 100; s -= 100) cout << "C";
    if (s / 10 == 9) {
      cout << "XC";
      s %= 10;
    }
    if (s >= 50) {
      cout << "L";
      s -= 50;
    }
    if (s / 10 == 4) {
      cout << "XL";
      s %= 10;
    }
    for (; s >= 10; s -= 10) cout << "X";
    if (s == 9) {
      cout << "IX";
      s = 0;
    }
    if (s >= 5) {
      cout << "V";
      s -= 5;
    }
    if (s == 4) {
      cout << "IV";
      s = 0;
    }
    for (; s > 0; s--) cout << "I";
  } else {
    if (s == 0)
      cout << 0;
    else {
      for (i = 0; i < b.length(); i++) d = d * 10 + (b[i] - 48);
      rec(s, d);
    }
  }
}
