#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
long long A;
string B, C;
string to_roman(int x) {
  string I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
  string X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
  string C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
  string M[] = {"", "M", "MM", "MMM"};
  string re;
  re = I[x % 10] + re;
  x /= 10;
  re = X[x % 10] + re;
  x /= 10;
  re = C[x % 10] + re;
  x /= 10;
  re = M[x % 10] + re;
  return re;
}
long long to_dec(string s, long long base) {
  long long re = 0;
  for (int a = (0); a <= ((int)((s).size()) - 1); a++)
    if ('0' <= s[a] && s[a] <= '9')
      re = re * base + (long long)(s[a] - '0');
    else if ('A' <= s[a] && s[a] <= 'Z')
      re = re * base + (long long)(s[a] - 'A' + 10);
  return re;
}
string to_to(long long num, long long base) {
  string re;
  while (num > 0) {
    long long rem = num % base;
    if (rem <= 9)
      re = string(1, '0' + rem) + re;
    else
      re = string(1, 'A' + rem - 10) + re;
    num /= base;
  }
  if (re == "") re = "0";
  return re;
}
int main() {
  cin >> A >> B >> C;
  long long z = to_dec(C, A);
  if (B == "R")
    cout << to_roman(z);
  else {
    int ba;
    sscanf(B.c_str(), "%d", &ba);
    cout << to_to(z, ba);
  }
  return 0;
}
