#include <bits/stdc++.h>
using namespace std;
int a, b = -1;
char c_in[2000];
char tmp1[2000], tmp2[2000];
pair<long long, const char*> rdigits[] = {
    make_pair(3000, "MMM"), make_pair(2000, "MM"),  make_pair(1000, "M"),
    make_pair(900, "CM"),   make_pair(800, "DCCC"), make_pair(700, "DCC"),
    make_pair(600, "DC"),   make_pair(500, "D"),    make_pair(400, "CD"),
    make_pair(300, "CCC"),  make_pair(200, "CC"),   make_pair(100, "C"),
    make_pair(90, "XC"),    make_pair(80, "LXXX"),  make_pair(70, "LXX"),
    make_pair(60, "LX"),    make_pair(50, "L"),     make_pair(40, "XL"),
    make_pair(30, "XXX"),   make_pair(20, "XX"),    make_pair(10, "X"),
    make_pair(9, "IX"),     make_pair(8, "VIII"),   make_pair(7, "VII"),
    make_pair(6, "VI"),     make_pair(5, "V"),      make_pair(4, "IV"),
    make_pair(3, "III"),    make_pair(2, "II"),     make_pair(1, "I")};
int rdigits_sz = sizeof(rdigits) / sizeof(*rdigits);
long long dec_dig(char c) {
  if (isdigit(c)) return c - '0';
  return 10 + toupper(c) - 'A';
}
char from_dec_to_ch(int digit) {
  if (digit < 0) throw 0;
  if (digit < 10) return '0' + digit;
  return 'A' + (digit - 10);
}
long long atoll(const char* str, long long radix) {
  int len = strlen(str);
  long long cur_deg = 1;
  long long res = 0;
  for (int i = len - 1; i >= 0; i--, cur_deg *= radix)
    res += dec_dig(str[i]) * cur_deg;
  return res;
}
void lltor(long long num) {
  if (num > 3000 || num <= 0) throw 0;
  while (num)
    for (int i = 0; i < rdigits_sz; i++)
      if (rdigits[i].first <= num) {
        printf("%s", rdigits[i].second);
        num -= rdigits[i].first;
        break;
      }
}
void lltoa(long long num, long long radix) {
  string res;
  while (num) {
    long long rem = num % radix;
    res.push_back(from_dec_to_ch(rem));
    num /= radix;
  }
  reverse(res.begin(), res.end());
  puts(res.empty() ? "0" : res.c_str());
}
int main() {
  char buf[100];
  scanf("%d%s%s", &a, &buf, &c_in);
  if (buf[0] != 'R')
    b = atoi(buf);
  else
    b = -1;
  long long c_dec = atoll(c_in, a);
  if (b == -1)
    lltor(c_dec);
  else
    lltoa(c_dec, b);
}
