#include <bits/stdc++.h>
using namespace std;
char s[1024], t[1024];
inline int c2d(char c) {
  return (c >= '0' && c <= '9') ? c - '0' : c - 'A' + 10;
}
inline char d2c(int d) { return (d <= 9) ? '0' + d : 'A' + d - 10; }
inline void putroman(int d, char c1, char c5, char c10) {
  if (d >= 1 && d <= 3)
    for (int i = 1; i <= d; i++) putchar(c1);
  else if (d == 4)
    putchar(c1), putchar(c5);
  else if (d >= 5 && d <= 8) {
    putchar(c5);
    for (int i = 6; i <= d; i++) putchar(c1);
  } else if (d == 9)
    putchar(c1), putchar(c10);
}
int main() {
  int a;
  char sb[16];
  scanf("%d%s%s", &a, sb, s);
  long long v = 0;
  for (char *cpt = s; *cpt; cpt++) v = v * a + c2d(*cpt);
  if (sb[0] == 'R') {
    putroman(v / 1000, 'M', '-', '-');
    putroman((v / 100) % 10, 'C', 'D', 'M');
    putroman((v / 10) % 10, 'X', 'L', 'C');
    putroman(v % 10, 'I', 'V', 'X');
    putchar('\n');
  } else {
    if (v == 0)
      puts("0");
    else {
      int b = atoi(sb), m = 0;
      while (v > 0) {
        t[m++] = d2c(v % b);
        v /= b;
      }
      for (int i = m - 1; i >= 0; i--) putchar(t[i]);
      putchar('\n');
    }
  }
  return 0;
}
