#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
long long a, n;
char str[5];
char num[N];
void gao(long long n, int b) {
  if (!n) return;
  gao(n / b, b);
  if (n % b < 10)
    printf("%d", n % b);
  else
    printf("%c", n % b - 10 + 'A');
}
string s[] = {"I", "V", "X", "L", "C", "D", "M"};
int main() {
  scanf("%I64d %s", &a, str);
  scanf("%s", num);
  for (int i = 0; num[i]; i++) {
    n = n * a + (num[i] > '9' ? (num[i] - 'A' + 10) : (num[i] - '0'));
  }
  if (str[0] == 'R') {
    int i = 0;
    string ans = "";
    while (n) {
      int p = n % 10;
      if (p == 1) ans = s[i] + ans;
      if (p == 2) ans = s[i] + s[i] + ans;
      if (p == 3) ans = s[i] + s[i] + s[i] + ans;
      if (p == 4) ans = s[i] + s[i + 1] + ans;
      if (p == 5) ans = s[i + 1] + ans;
      if (p == 6) ans = s[i + 1] + s[i] + ans;
      if (p == 7) ans = s[i + 1] + s[i] + s[i] + ans;
      if (p == 8) ans = s[i + 1] + s[i] + s[i] + s[i] + ans;
      if (p == 9) ans = s[i] + s[i + 2] + ans;
      i += 2;
      n /= 10;
    }
    cout << ans << endl;
  } else {
    int b;
    sscanf(str, "%d", &b);
    if (n == 0) printf("0");
    gao(n, b);
    puts("");
  }
  return 0;
}
