#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
string res, c, s;
int r, a, i, b;
char t[5], t2[1005];
string przerob(string c, int a, int b) {
  long long r = 0;
  int k;
  string res = "";
  for (i = 0; i < c.size(); i++) {
    r *= a;
    if (c[i] <= '9')
      r += int(c[i]) - '0';
    else
      r += int(c[i]) - 'A' + 10;
  }
  if (r == 0) return "0";
  while (r) {
    k = r % b;
    if (k <= 9)
      res = char(k + 48) + res;
    else
      res = char(k + 55) + res;
    r /= b;
  }
  return res;
}
int main() {
  scanf("%d %s %s", &a, &t, &t2);
  c = t2;
  if (t[0] == 'R') {
    r = 0;
    for (i = 0; i < c.size(); i++) {
      r *= a;
      if (c[i] <= '9')
        r += int(c[i]) - '0';
      else
        r += int(c[i]) - 'A' + 10;
    }
    res = "";
    while (r) {
      if (r >= 1000) {
        res += "M";
        r -= 1000;
      } else if (r >= 900) {
        res += "CM";
        r -= 900;
      } else if (r >= 500) {
        res += "D";
        r -= 500;
      } else if (r >= 400) {
        res += "CD";
        r -= 400;
      } else if (r >= 100) {
        res += "C";
        r -= 100;
      } else if (r >= 90) {
        res += "XC";
        r -= 90;
      } else if (r >= 50) {
        res += "L";
        r -= 50;
      } else if (r >= 40) {
        res += "XL";
        r -= 40;
      } else if (r >= 10) {
        res += "X";
        r -= 10;
      } else if (r >= 9) {
        res += "IX";
        r -= 9;
      } else if (r >= 5) {
        res += "V";
        r -= 5;
      } else if (r >= 4) {
        res += "IV";
        r -= 4;
      } else if (r >= 1) {
        res += "I";
        r -= 1;
      }
    }
    printf("%s\n", res.c_str());
  } else {
    s = t;
    if (s.size() == 1)
      b = int(s[0]) - 48;
    else
      b = (int(s[0]) - 48) * 10 + int(s[1]) - 48;
    cout << przerob(c, a, b) << endl;
  }
  return 0;
}
