#include <bits/stdc++.h>
using namespace std;
long long test(char x) {
  if ('0' <= x && x <= '9') return x - '0';
  if ('A' <= x && x <= 'Z') return 10 + x - 'A';
}
long long convert(string s, long long base) {
  long long ans = 0;
  for (int i = 0; i < s.length(); i++) ans = ans * base + test(s[i]);
  return ans;
}
void reconvert(long long tmp, long long base) {
  if (tmp >= base) reconvert(tmp / base, base);
  if (tmp % base < 10)
    cout << tmp % base;
  else
    cout << char(tmp % base - 10 + 'A');
}
void roman(long long aa) {
  for (int i = 0; i < aa / 1000; i++) cout << "M";
  aa %= 1000;
  if (aa >= 900) {
    cout << "CM";
    aa %= 900;
  }
  for (int i = 0; i < aa / 500; i++) cout << "D";
  aa %= 500;
  if (aa >= 400) {
    cout << "CD";
    aa %= 400;
  }
  for (int i = 0; i < aa / 100; i++) cout << "C";
  aa %= 100;
  if (aa >= 90) {
    cout << "XC";
    aa %= 90;
  }
  for (int i = 0; i < aa / 50; i++) cout << "L";
  aa %= 50;
  if (aa >= 40) {
    cout << "XL";
    aa %= 40;
  }
  for (int i = 0; i < aa / 10; i++) cout << "X";
  aa %= 10;
  if (aa >= 9) {
    cout << "IX";
    aa %= 9;
  }
  for (int i = 0; i < aa / 5; i++) cout << "V";
  aa %= 5;
  if (aa >= 4) {
    cout << "IV";
    aa %= 4;
  }
  for (int i = 0; i < aa; i++) cout << "I";
}
int main() {
  int a;
  string b;
  scanf("%d", &a);
  cin >> b;
  string s;
  cin >> s;
  long long tmp = convert(s, a);
  if (b != "R") {
    int bb = 0;
    for (int i = 0; i < b.length(); i++) bb = bb * 10 + (b[i] - '0');
    reconvert(tmp, bb);
    return 0;
  }
  roman(tmp);
}
