#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
const double pi = 3.1415926535897932384626433832795;
void pos(long long n, int p) {
  if (n == 0) cout << 0;
  string res = "";
  while (n != 0) {
    int t = n % p;
    char c = '0' + t;
    if (t > 9) c = 'A' + t - 10;
    res += c;
    n /= p;
  }
  reverse(res.begin(), res.end());
  cout << res;
}
void rom(long long n) {
  string res = "";
  while (n) {
    if (n - 1000 >= 0) {
      res += "M";
      n -= 1000;
      continue;
    }
    if (n - 900 >= 0) {
      res += "CM";
      n -= 900;
      continue;
    }
    if (n - 500 >= 0) {
      res += "D";
      n -= 500;
      continue;
    }
    if (n - 400 >= 0) {
      res += "CD";
      n -= 400;
      continue;
    }
    if (n - 100 >= 0) {
      res += "C";
      n -= 100;
      continue;
    }
    if (n - 90 >= 0) {
      res += "XC";
      n -= 90;
      continue;
    }
    if (n - 50 >= 0) {
      res += "L";
      n -= 50;
      continue;
    }
    if (n - 40 >= 0) {
      res += "XL";
      n -= 40;
      continue;
    }
    if (n - 10 >= 0) {
      res += "X";
      n -= 10;
      continue;
    }
    if (n - 9 >= 0) {
      res += "IX";
      n -= 9;
      continue;
    }
    if (n - 5 >= 0) {
      res += "V";
      n -= 5;
      continue;
    }
    if (n - 4 >= 0) {
      res += "IV";
      n -= 4;
      continue;
    }
    if (n - 1 >= 0) {
      res += "I";
      n -= 1;
      continue;
    }
  }
  cout << res;
}
long long toDec(string s, int d) {
  long long res = 0;
  long long p = 1;
  for (int i = s.length() - 1; i >= 0; --i) {
    if (s[i] <= '9')
      res += (s[i] - '0') * p;
    else
      res += (s[i] - 'A' + 10) * p;
    p *= d;
  }
  return res;
}
int main() {
  int a;
  string s;
  cin >> a >> s;
  string c;
  cin >> c;
  long long t = toDec(c, a);
  if (s == "R") {
    rom(t);
  } else {
    int p = atoi(s.c_str());
    pos(t, p);
  }
  return 0;
}
