#include <bits/stdc++.h>
using namespace std;
char toc(int x) {
  if (x < 10)
    return x + 48;
  else
    return x + 55;
}
int toi(char x) {
  if (x - 48 < 10)
    return x - 48;
  else
    return x - 55;
}
long long pw(long long x, int n) {
  if (n == 0) return 1;
  if (n == 1) return x;
  long long ans = pw(x, n / 2);
  ans *= ans;
  if (n % 2) ans *= x;
  return ans;
}
int main() {
  int a, b;
  string B, c;
  cin >> a >> B >> c;
  long long num = 0;
  for (int i = c.length() - 1, ind = 0; i >= 0; i--, ind++) {
    num += pw(a, ind) * toi(c[i]);
  }
  if (B != "R") {
    if (B.length() == 1)
      b = toi(B[0]);
    else
      b = toi(B[0]) * 10 + toi(B[1]);
    if (!num) {
      cout << 0;
      return 0;
    }
    stack<char> st;
    while (num) {
      st.push(toc(num % b));
      num /= b;
    }
    while (!st.empty()) {
      cout << st.top();
      st.pop();
    }
  } else {
    int M = num / 1000;
    num -= M * 1000;
    int D = num / 500;
    num -= D * 500;
    int C = num / 100;
    num -= C * 100;
    int L = num / 50;
    num -= L * 50;
    int X = num / 10;
    num -= X * 10;
    int V = num / 5;
    num -= V * 5;
    int I = num;
    for (int i = 0; i < M; i++) cout << "M";
    if (D && C > 3)
      cout << "CM";
    else if (C <= 3) {
      if (D) cout << "D";
      for (int i = 0; i < C; i++) cout << "C";
    } else if (C == 4) {
      cout << "CD";
    }
    if (L && X > 3)
      cout << "XC";
    else if (X <= 3) {
      if (L) cout << "L";
      for (int i = 0; i < X; i++) cout << "X";
    } else if (X == 4) {
      cout << "XL";
    }
    if (V && I > 3)
      cout << "IX";
    else if (I <= 3) {
      if (V) cout << "V";
      for (int i = 0; i < I; i++) cout << "I";
    } else if (I == 4) {
      cout << "IV";
    }
  }
  return 0;
}
