#include <bits/stdc++.h>
using namespace std;
int digit[] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
string symb[] = {"I",  "IV", "V",  "IX", "X",  "XL", "L",
                 "XC", "C",  "CD", "D",  "CM", "M"};
string to_R(long long a) {
  string res;
  int x(12);
  while (x >= 0) {
    while (a >= digit[x]) {
      a -= digit[x];
      res += symb[x];
    }
    --x;
  }
  return res;
}
long long to_d(string c, long long base) {
  long long res(0);
  for (int i(0); i < c.size(); ++i) {
    res *= base;
    if (isdigit(c[i]))
      res += c[i] - '0';
    else
      res += 10 + c[i] - 'A';
  }
  return res;
}
string to_ans(long long a, long long base) {
  string res;
  long long di(base);
  while (a) {
    int d(a % di);
    if (d < 10)
      res += (char)(d + '0');
    else
      res += (char)(d - 10 + 'A');
    a /= di;
  }
  reverse(res.begin(), res.end());
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  long long a;
  string b, c;
  cin >> a >> b >> c;
  long long x(to_d(c, a));
  if (!x) {
    cout << 0;
    return 0;
  }
  if (b == "R")
    cout << to_R(x);
  else {
    int base(0);
    for (int i(0); i < b.size(); ++i) {
      base = base * 10 + b[i] - '0';
    }
    cout << to_ans(x, base);
  }
}
