#include <bits/stdc++.h>
using namespace std;
string decimalToRoman(int n) {
  const string rom[13] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                          "XL", "X",  "IX", "V",  "IV", "I"};
  const int dec[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
  string ret = "";
  for (int i = 0; i < 13; i++) {
    while (n >= dec[i]) {
      n -= dec[i];
      ret += rom[i];
    }
  }
  return ret;
}
long long toDecimal(char *s, int b) {
  int n = strlen(s);
  long long ret = 0;
  long long mul = 1;
  for (int i = n - 1; i >= 0; i--, mul *= b) {
    if (s[i] >= 'A')
      ret += (s[i] - 'A' + 10) * mul;
    else
      ret += (s[i] - '0') * mul;
  }
  return ret;
}
string toBase(long long n, int b) {
  if (n == 0) return "0";
  string ret = "";
  while (n) {
    int c = n % b;
    if (c >= 10)
      ret.push_back(c - 10 + 'A');
    else
      ret.push_back(c + '0');
    n /= b;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
int main(void) {
  int a, b;
  char bs[8];
  long long c;
  char cs[1024];
  scanf("%d %s\n%s\n", &a, bs, cs);
  b = bs[0] == 'R' ? -1 : atoi(bs);
  c = toDecimal(cs, a);
  if (b == -1)
    printf("%s\n", decimalToRoman(c).c_str());
  else
    printf("%s\n", toBase(c, b).c_str());
  return 0;
}
