#include <bits/stdc++.h>
using namespace std;
long long values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
string roman[] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                  "XL", "X",  "IX", "V",  "IV", "I"};
string toRoman(long long n) {
  string resp = "";
  for (int i = 0; i < 13; i++) {
    while (n >= values[i]) {
      n -= values[i];
      resp += roman[i];
    }
  }
  return resp;
}
long long to10(string s, int b) {
  long long resp = 0;
  for (int i = 0; i < s.size(); i++) {
    resp *= b;
    if (isalpha(s[i]))
      resp += (s[i] - 'A' + 10);
    else
      resp += (s[i] - '0');
  }
  return resp;
}
string toBase(long long n, string x) {
  int b, digit;
  sscanf(x.c_str(), "%d", &b);
  string resp = "";
  while (n) {
    digit = n % b;
    n /= b;
    if (digit >= 10)
      resp += ('A' + digit - 10);
    else
      resp += ('0' + digit);
  }
  resp = string(resp.rbegin(), resp.rend());
  return resp;
}
string dim(string s) {
  string resp = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') continue;
    resp += s[i];
  }
  return (resp == "" ? "0" : resp);
}
int main() {
  int a;
  string b, c;
  cin >> a >> b >> c;
  if (dim(c) == "0") {
    printf("0\n");
    return 0;
  }
  long long b10 = to10(c, a);
  if (b == "R")
    cout << toRoman(b10) << endl;
  else
    cout << toBase(b10, b) << endl;
  return 0;
}
