#include <bits/stdc++.h>
using namespace std;
int a, b;
long long now;
char str[1111];
void out() {
  if (!now) {
    cout << now << endl;
    return;
  }
  string s;
  while (now) {
    int x = now % b;
    if (x >= 10)
      s += (x - 10 + 'A');
    else
      s += (x + '0');
    now /= b;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}
map<char, int> mp;
void work() {
  mp['I'] = 1;
  mp['V'] = 5;
  mp['X'] = 10;
  mp['L'] = 50;
  mp['C'] = 100;
  mp['D'] = 500;
  mp['M'] = 1000;
  int a[5] = {0};
  a[0] = now % 10, a[1] = (now / 10) % 10, a[2] = (now / 100) % 10,
  a[3] = now / 1000;
  string tmp;
  if (a[3]) {
    for (int i = 0; i < a[3]; i++) tmp += 'M';
  }
  if (a[2]) {
    if (a[2] < 4) {
      for (int i = 0; i < a[2]; i++) tmp += 'C';
    } else if (a[2] == 4) {
      tmp += "CD";
    } else if (a[2] < 9) {
      tmp += 'D';
      for (int i = 5; i < a[2]; i++) tmp += 'C';
    } else
      tmp += "CM";
  }
  if (a[1]) {
    if (a[1] < 4) {
      for (int i = 0; i < a[1]; i++) tmp += 'X';
    } else if (a[1] == 4) {
      tmp += "XL";
    } else if (a[1] < 9) {
      tmp += 'L';
      for (int i = 5; i < a[1]; i++) tmp += 'X';
    } else
      tmp += "XC";
  }
  if (a[0]) {
    if (a[0] < 4) {
      for (int i = 0; i < a[0]; i++) tmp += 'I';
    } else if (a[0] == 4) {
      tmp += "IV";
    } else if (a[0] < 9) {
      tmp += 'V';
      for (int i = 5; i < a[0]; i++) tmp += 'I';
    } else
      tmp += "IX";
  }
  cout << tmp << endl;
}
int main() {
  cin >> a >> str;
  bool flag = true;
  if (str[0] != 'R') {
    flag = false;
    int len = strlen(str);
    for (int i = 0; i < len; i++) b = b * 10 + str[i] - '0';
  }
  cin >> str;
  int len = strlen(str);
  for (int i = 0; i < len; i++) {
    if (isalpha(str[i]))
      now = now * a + str[i] - 'A' + 10;
    else
      now = now * a + str[i] - '0';
  }
  if (!flag)
    out();
  else
    work();
  return 0;
}
