#include <bits/stdc++.h>
using namespace std;
const int ROMAN_BASE = -1;
string toRoman(long long number) {
  assert(number < 4000);
  assert(number > 0);
  vector<pair<string, int>> romanDigits = {
      {"I", 1},   {"IV", 4},   {"V", 5},   {"IX", 9},  {"X", 10},
      {"XL", 40}, {"L", 50},   {"XC", 90}, {"C", 100}, {"CD", 400},
      {"D", 500}, {"CM", 900}, {"M", 1000}};
  reverse(romanDigits.begin(), romanDigits.end());
  int rem = number;
  string res = "";
  while (rem > 0) {
    for (auto cur : romanDigits) {
      int cur_num = cur.second;
      if (cur_num <= rem) {
        rem -= cur_num;
        res += cur.first;
        break;
      }
    }
  }
  return res;
}
void lltoa(long long n, char* result, int base) {
  assert(base > 1);
  assert(base <= 10 + 26);
  auto getBaseDigit = [](int num, int base) {
    assert(num >= 0 && num < base);
    if (num < 10) {
      return '0' + num;
    }
    return num - 10 + 'A';
  };
  int cur_index = 0;
  while (n > 0) {
    int cur = n % base;
    char cur_digit = getBaseDigit(cur, base);
    result[cur_index++] = cur_digit;
    n /= base;
  }
  result[cur_index] = '\0';
  reverse(result, result + cur_index);
}
string solve(int a, int b, const string& c) {
  long long number = stoll(c, 0, a);
  if (number == 0LL) return "0";
  const int MAX_RES_LEN = 100;
  if (b != ROMAN_BASE) {
    char result[MAX_RES_LEN];
    lltoa(number, result, b);
    return string(result);
  }
  return toRoman(number);
}
int main() {
  int a;
  int b;
  cin >> a;
  const int MAX_BASE_LEN = 100;
  char b_base[MAX_BASE_LEN];
  cin >> b_base;
  if (strcmp(b_base, "R") == 0) {
    b = ROMAN_BASE;
  } else {
    sscanf(b_base, "%d", &b);
  }
  string c;
  cin >> c;
  cout << solve(a, b, c);
  return 0;
}
