#include <bits/stdc++.h>
using namespace std;
int charToDec(char c) {
  if ((c >= '0') && (c <= '9')) return c - '0';
  if ((c >= 'A') && (c <= 'Z')) return c - 'A' + 10;
}
char decToChar(int c) {
  if ((c >= 0) && (c <= 9)) return c + '0';
  if ((c >= 10) && (c <= 26)) return c + 'A' - 10;
}
long long hzToDec(string s, int a) {
  long long r = 0;
  for (int i = 0; i < s.length(); i++) {
    r *= a;
    r += charToDec(s[i]);
  }
  return r;
}
string decToHz(long long x, int a) {
  string s = "";
  while (x > 0) {
    s = decToChar(x % a) + s;
    x = x / a;
  }
  if (s == "") s = "0";
  return s;
}
string toRome(long long X) {
  string r[3100];
  r[3000] = "MMM";
  r[2000] = "MM";
  r[1000] = "M";
  r[900] = "CM";
  r[800] = "DCCC";
  r[700] = "DCC";
  r[600] = "DC";
  r[500] = "D";
  r[400] = "CD";
  r[300] = "CCC";
  r[200] = "CC";
  r[100] = "C";
  r[90] = "XC";
  r[80] = "LXXX";
  r[70] = "LXX";
  r[60] = "LX";
  r[50] = "L";
  r[40] = "XL";
  r[30] = "XXX";
  r[20] = "XX";
  r[10] = "X";
  r[9] = "IX";
  r[8] = "VIII";
  r[7] = "VII";
  r[6] = "VI";
  r[5] = "V";
  r[4] = "IV";
  r[3] = "III";
  r[2] = "II";
  r[1] = "I";
  return r[X / 1000 * 1000] + r[(X % 1000) / 100 * 100] +
         r[(X % 100) / 10 * 10] + r[X % 10];
}
int main() {
  int a, b;
  string bb, x;
  long long x10;
  cin >> a >> bb >> x;
  x10 = hzToDec(x, a);
  if (bb == "R") {
    cout << toRome(x10);
  } else
    cout << decToHz(x10, atoi(bb.c_str()));
  return 0;
}
