#include <bits/stdc++.h>
using namespace std;
inline int getv(char c) {
  if (c <= '9') return c - '0';
  return c - 'A' + 10;
}
inline char getn(int x) {
  if (x < 10) return x + '0';
  return x - 10 + 'A';
}
std::string to_roman(int value) {
  struct romandata_t {
    int value;
    char const* numeral;
  };
  static romandata_t const romandata[] = {
      1000, "M",  900, "CM", 500, "D",  400, "CD", 100, "C",
      90,   "XC", 50,  "L",  40,  "XL", 10,  "X",  9,   "IX",
      5,    "V",  4,   "IV", 1,   "I",  0,   NULL};
  std::string result;
  for (romandata_t const* current = romandata; current->value > 0; ++current) {
    while (value >= current->value) {
      result += current->numeral;
      value -= current->value;
    }
  }
  return result;
}
int main(int argc, char** argv) {
  int a;
  string bb, c;
  cin >> a >> bb >> c;
  if (bb != "R") {
    int b;
    sscanf(bb.c_str(), "%d", &b);
    long long res = 0;
    int L = c.length();
    for (int i = (0); i < (L); ++i) res = (res * a) + getv(c[i]);
    string r;
    for (; res; res /= b) r = getn(res % b) + r;
    if (r == "") r = "0";
    cout << r << endl;
  } else {
    long long res = 0;
    int L = c.length();
    for (int i = (0); i < (L); ++i) res = (res * a) + getv(c[i]);
    cout << to_roman(res) << endl;
  }
  return 0;
}
