#include <bits/stdc++.h>
using namespace std;
int main() {
  long long base;
  string b;
  string c;
  cin >> base >> b >> c;
  int n = c.size();
  long long add = 1;
  long long mark = 0;
  long long now;
  for (int i = n - 1; i >= 0; i--) {
    if (c[i] >= '0' && c[i] <= '9')
      now = c[i] - '0';
    else
      now = 10 + c[i] - 'A';
    mark += add * now;
    add *= base;
  }
  long long stack[1010];
  int pos = 0;
  if (b[0] == 'R') {
    b = "";
    if (mark >= 1000) {
      b += 'M';
      mark -= 1000;
    }
    if (mark >= 1000) {
      b += 'M';
      mark -= 1000;
    }
    if (mark >= 1000) {
      b += 'M';
      mark -= 1000;
    }
    if (mark >= 900) {
      b += "CM";
      mark -= 900;
    }
    if (mark >= 500) {
      b += 'D';
      mark -= 500;
    }
    if (mark >= 400) {
      b += "CD";
      mark -= 400;
    }
    if (mark >= 100) {
      b += 'C';
      mark -= 100;
    }
    if (mark >= 100) {
      b += 'C';
      mark -= 100;
    }
    if (mark >= 100) {
      b += 'C';
      mark -= 100;
    }
    if (mark >= 100) {
      b += 'C';
      mark -= 100;
    }
    if (mark >= 90) {
      b += "XC";
      mark -= 90;
    }
    if (mark >= 50) {
      b += 'L';
      mark -= 50;
    }
    if (mark >= 40) {
      b += "XL";
      mark -= 40;
    }
    if (mark >= 10) {
      b += 'X';
      mark -= 10;
    }
    if (mark >= 10) {
      b += 'X';
      mark -= 10;
    }
    if (mark >= 10) {
      b += 'X';
      mark -= 10;
    }
    if (mark >= 10) {
      b += 'X';
      mark -= 10;
    }
    if (mark >= 9) {
      b += "IX";
      mark -= 9;
    }
    if (mark >= 5) {
      b += 'V';
      mark -= 5;
    }
    if (mark >= 4) {
      b += "IV";
      mark -= 4;
    }
    if (mark == 1)
      b += 'I';
    else if (mark == 2)
      b += "II";
    else if (mark == 3)
      b += "III";
    cout << b << endl;
  } else {
    if (mark == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (b.size() == 1)
      base = b[0] - '0';
    else
      base = (b[0] - '0') * 10 + b[1] - '0';
    while (mark) {
      stack[pos++] = mark % base;
      mark /= base;
    }
    b = "";
    for (int i = pos - 1; i >= 0; i--) {
      now = stack[i];
      if (now >= 10)
        b += now - 10 + 'A';
      else
        b += now + '0';
    }
    cout << b << endl;
  }
  return 0;
}
