#include <bits/stdc++.h>
using namespace std;
string toBase(long long num, int b) {
  string out = "";
  int ntmp;
  while (num > 0) {
    ntmp = num % b;
    if (ntmp > 9)
      out += ntmp - 10 + 'A';
    else
      out += ntmp + '0';
    num /= b;
  }
  reverse(out.begin(), out.end());
  return (out.length() ? out : "0");
}
long long toDec(string c, int b) {
  long long p = 1, num = 0;
  int flag, i;
  string cp;
  for (i = 0; i < c.length(); i++) {
    if (c[i] != '0') flag = 1;
    if (flag) cp += c[i];
  }
  reverse(cp.begin(), cp.end());
  for (i = 0; i < cp.length(); i++) {
    if (cp[i] > '9') {
      if (cp[i] >= 'a')
        num += p * (cp[i] - 'a' + 10);
      else if (cp[i] >= 'A')
        num += p * (cp[i] - 'A' + 10);
    } else {
      num += p * (cp[i] - '0');
    }
    p *= b;
  }
  return num;
}
string G(int num) {
  int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
  string numerals[] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                       "XL", "X",  "IX", "V",  "IV", "I"};
  string out = "";
  for (int i = 0; i < 13; i++) {
    while (num >= values[i]) {
      num -= values[i];
      out += numerals[i];
    }
  }
  return out;
}
int main() {
  string out, firstline, tmp, c;
  int a, i, b = 0;
  getline(cin, firstline);
  stringstream ss;
  ss.str(firstline);
  ss >> a >> b;
  cin >> c;
  if (b) {
    out = toBase(toDec(c, a), b);
  } else {
    out = G(toDec(c, a));
  }
  cout << out << endl;
  return 0;
}
