#include <bits/stdc++.h>
using namespace std;
int a, b, c;
char q[1000000], num[1000000], u[1000000];
long long A = 0;
string temp1, temp2;
string toRoman(int n) {
  string ans = "";
  if (n == 0) return ans;
  while (n >= 1000) {
    n -= 1000;
    ans = ans + "M";
  }
  if (n >= 900) return ans + "CM" + toRoman(n - 900);
  while (n >= 500) {
    n -= 500;
    ans = ans + "D";
  }
  if (n >= 400) {
    return ans + "CD" + toRoman(n - 400);
  }
  while (n >= 100) {
    n -= 100;
    ans = ans + "C";
  }
  if (n >= 90) {
    return ans + "XC" + toRoman(n - 90);
  }
  while (n >= 50) {
    n -= 50;
    ans = ans + "L";
  }
  if (n >= 40) {
    return ans + "XL" + toRoman(n - 40);
  }
  while (n >= 10) {
    n -= 10;
    ans = ans + "X";
  }
  if (n >= 9) {
    return ans + "IX" + toRoman(n - 9);
  }
  while (n >= 5) {
    n -= 5;
    ans = ans + "V";
  }
  if (n >= 4) {
    return ans + "IV" + toRoman(n - 4);
  }
  while (n > 0) {
    n -= 1;
    ans = ans + "I";
  }
  return ans;
}
int main() {
  scanf("%d %s\n%s", &a, q, num);
  temp1 = q;
  temp2 = num;
  int n = temp2.length();
  for (int i = 0; i < n; ++i) {
    A *= a;
    if (num[i] <= '9' && num[i] >= '0') {
      A += int(num[i] - '0');
    } else {
      A += int(num[i] - 'A') + 10;
    }
  }
  if (temp1 != "R") {
    sscanf(q, "%d", &b);
    {
      string ans = "";
      while (A) {
        int r = A % b;
        if (r < 10) {
          sprintf(u, "%c", char(r + (int)'0'));
        } else {
          sprintf(u, "%c", char(r - 10 + (int)'A'));
        }
        string temp = u;
        ans = temp + ans;
        A /= b;
      }
      if (ans == "")
        printf("0\n");
      else
        printf("%s\n", ans.c_str());
    }
  } else {
    string ans = toRoman(A);
    if (ans == "")
      printf("0\n");
    else
      printf("%s\n", ans.c_str());
  }
  return 0;
}
