#include <bits/stdc++.h>
const double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;
string getRim(long long x) {
  string ans;
  while (x >= 1000) {
    x -= 1000;
    ans.push_back('M');
  }
  while (x >= 900) {
    ans += "CM";
    x -= 900;
  }
  while (x >= 500) {
    ans.push_back('D');
    x -= 500;
  }
  while (x >= 400) {
    ans += "CD";
    x -= 400;
  }
  while (x >= 100) {
    ans.push_back('C');
    x -= 100;
  }
  while (x >= 90) {
    ans += "XC";
    x -= 90;
  }
  while (x >= 50) {
    ans.push_back('L');
    x -= 50;
  }
  while (x >= 40) {
    ans += "XL";
    x -= 40;
  }
  while (x >= 10) {
    ans.push_back('X');
    x -= 10;
  }
  while (x >= 9) {
    ans += "IX";
    x -= 9;
  }
  while (x >= 5) {
    ans.push_back('V');
    x -= 5;
  }
  while (x >= 4) {
    ans += "IV";
    x -= 4;
  }
  while (x >= 1) {
    ans.push_back('I');
    x--;
  }
  return ans;
}
long long get1(string x, long long base) {
  long long res = 0;
  for (int i = 0; i < x.size(); i++) {
    int ch;
    if (x[i] <= '9')
      ch = x[i] - '0';
    else
      ch = x[i] - 'A' + 10;
    res = res * base + ch;
  }
  return res;
}
string get2(long long x, long long base) {
  string ans;
  while (1) {
    if (x == 0) {
      break;
    }
    long long ch = x % base;
    x /= base;
    if (ch < 10) {
      ans.push_back((char)ch + '0');
    } else {
      ans.push_back((char)ch - 10 + 'A');
    }
  }
  if (ans.size() == 0) {
    ans.push_back('0');
  }
  reverse((ans).begin(), (ans).end());
  return ans;
}
void solve() {
  long long a;
  string s, c;
  cin >> a >> s >> c;
  long long x = get1(c, a);
  if (s[0] == 'R') {
    cout << getRim(x) << endl;
  } else {
    int b = atoi(s.c_str());
    cout << get2(x, b) << endl;
  }
}
int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(7);
  int step = 1;
  for (int i = 0; i < step; i++) {
    solve();
  }
}
