#include <bits/stdc++.h>
using namespace std;
int a;
string b, c;
int main() {
  cin >> a;
  cin >> b >> c;
  while ((int)c.size() && c[0] == '0') c.erase(0, 1);
  if (!(int)c.size()) c = "0";
  long long val = 0;
  for (int(i) = 0; (i) < ((int)c.size()); ++(i)) {
    val = val * a;
    if (c[i] >= '0' && c[i] <= '9')
      val += c[i] - '0';
    else
      val += c[i] - 'A' + 10;
  }
  if (b != "R") {
    string ans = "";
    int to = atoi(b.c_str());
    while (val) {
      if (val % to < 10)
        ans += '0' + (int)(val % to);
      else
        ans += 'A' + (int)(val % to - 10);
      val /= to;
    }
    reverse((ans).begin(), (ans).end());
    if (!(int)ans.size()) ans = "0";
    cout << ans << endl;
  } else {
    int vals[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
    string r[13] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                    "XL", "X",  "IX", "V",  "IV", "I"};
    string ans = "";
    for (int(i) = 0; (i) < (13); ++(i))
      while (val >= vals[i]) {
        ans += r[i];
        val -= vals[i];
      }
    cout << ans << endl;
  }
}
