#include <bits/stdc++.h>
using namespace std;
template <typename T>
int size(T& a) {
  return (int)a.size();
}
template <typename T>
T sqr(T a) {
  return a * a;
}
char s[1002];
string romanian(long long number) {
  string res = "";
  int cthous = number / 1000;
  for (int i = (0); i < (cthous); ++i) res += "M";
  number %= 1000;
  if (number / 100 == 9) {
    res += "CM";
    number -= 900;
  }
  if (number / 100 >= 5) {
    res += "D";
    number -= 500;
  }
  if (number / 100 == 4) {
    res += "CD";
    number -= 400;
  }
  for (int i = (0); i < ((number / 100)); ++i) res += "C";
  number %= 100;
  if (number / 10 == 9) {
    res += "XC";
    number -= 90;
  }
  if (number / 10 >= 5) {
    res += "L";
    number -= 50;
  }
  if (number / 10 == 4) {
    res += "XL";
    number -= 40;
  }
  for (int i = (0); i < ((number / 10)); ++i) res += "X";
  number %= 10;
  if (number == 9) {
    res += "IX";
    number -= 90;
  }
  if (number >= 5) {
    res += "V";
    number -= 5;
  }
  if (number == 4) {
    res += "IV";
    number -= 4;
  }
  for (int i = (0); i < (number); ++i) res += "I";
  return res;
}
int parse(string& s) {
  int number = 0;
  for (int i = (0); i < (size(s)); ++i) number = number * 10 + (s[i] - '0');
  return number;
}
int main() {
  int a;
  string ss;
  cin >> a >> ss;
  scanf("\n");
  gets(s);
  long long number = 0;
  int n = strlen(s);
  for (int i = (0); i < (n); ++i)
    number = number * a +
             (s[i] >= 'A' && s[i] <= 'Z' ? s[i] - 'A' + 10 : s[i] - '0');
  if (ss == "R") {
    cout << romanian(number);
  } else {
    int b = parse(ss);
    vector<char> tmp;
    if (number == 0) {
      cout << "0";
      exit(0);
    }
    while (number) {
      tmp.push_back(number % b >= 10 ? (number % b - 10 + 'A')
                                     : (number % b + '0'));
      number /= b;
    }
    reverse(tmp.begin(), tmp.end());
    for (int i = (0); i < (size(tmp)); ++i) cout << tmp[i];
  }
  return 0;
}
