#include <bits/stdc++.h>
using namespace std;
long long convert(string inpt, int base) {
  if (inpt[0] == '-') return 0 - convert(inpt.substr(1, inpt.length()), base);
  long long answer = 0;
  for (unsigned i = 0; i < inpt.length(); ++i)
    if (isdigit(inpt[i])) {
      answer *= base;
      answer += inpt[i] - '0';
    } else {
      answer *= base;
      answer += inpt[i] - 'A' + 10;
    }
  return answer;
}
string iToString(int i) {
  ostringstream oss;
  oss << i;
  return oss.str();
}
string convert2roman(int n) {
  if (n > 3999) return "Largest number handled is 3999";
  if (n < 1) return "Smallest number handled is 1";
  string nStr = iToString(n);
  string rm;
  for (size_t i = 0; i < nStr.length(); ++i) {
    int msd = nStr[i] - '0';
    char s1[] = "IVXLCDM";
    char s2[] = "XLCDM**";
    for (size_t j = 0; j < rm.size(); ++j) {
      for (size_t k = 0; k < 7; ++k)
        if (rm[j] == s1[k]) {
          rm[j] = s2[k];
          break;
        }
    }
    string romanNum[] = {"",  "I",  "II",  "III",  "IV",
                         "V", "VI", "VII", "VIII", "IX"};
    rm = rm + romanNum[msd];
  }
  return rm;
}
string prn(long long x, string base) {
  if (x == 0) return "0";
  if (x < 0) return "-" + prn(0 - x, base);
  vector<int> toret;
  stringstream c;
  c << base;
  int b;
  c >> b;
  while (x) {
    toret.push_back(x % b);
    x /= b;
  }
  string ret = "";
  for (int i = toret.size() - 1; i >= 0; --i) {
    string add = " ";
    if (toret[i] < 10)
      add[0] = toret[i] + '0';
    else
      add[0] = toret[i] - 10 + 'A';
    ret = ret + add;
  }
  return ret;
}
int main() {
  int a;
  string b;
  cin >> a >> b;
  long long x;
  string inpt;
  cin >> inpt;
  x = convert(inpt, a);
  cerr << "Answer is:" << x << endl;
  if (b == "R")
    cout << convert2roman(x) << endl;
  else
    cout << prn(x, b) << endl;
  return 0;
}
