#include <bits/stdc++.h>
using namespace std;
string _(int n, char a, char b, char c) {
  if (n == 9) return string() + a + c;
  if (n == 4) return string() + a + b;
  string ret;
  if (n >= 5) ret += b;
  for (int i = 0; i < n % 5; i++) ret += a;
  return ret;
}
void run() {
  int a, b;
  long long d = 0;
  string s, c, ans;
  cin >> a >> s >> c;
  for (int i = 0; i < c.size(); i++)
    d *= a, d += isdigit(c[i]) ? c[i] - '0' : c[i] - 'A' + 10;
  if (s == "R") {
    cout << _(d / 1000, 'M', 'M', 'M') + _(d / 100 % 10, 'C', 'D', 'M') +
                _(d / 10 % 10, 'X', 'L', 'C') + _(d % 10, 'I', 'V', 'X')
         << endl;
  } else {
    b = atoi(s.c_str());
    for (; d; d /= b)
      ans.push_back(d % b < 10 ? d % b + '0' : d % b - 10 + 'A');
    reverse((ans).begin(), (ans).end());
    cout << (ans.empty() ? "0" : ans) << endl;
  }
}
int main() {
  run();
  return 0;
}
