#include <bits/stdc++.h>
using namespace std;
void roman(int e) {
  int a, b, c, d;
  a = (e / 1000) * 1000;
  b = ((e / 100) % 10) * 100;
  c = ((e / 10) % 10) * 10;
  d = ((e / 1) % 10) * 1;
  if (a == 1000)
    printf("M");
  else if (a == 2000)
    printf("MM");
  else if (a == 3000)
    printf("MMM");
  if (b == 100)
    printf("C");
  else if (b == 200)
    printf("CC");
  else if (b == 300)
    printf("CCC");
  else if (b == 400)
    printf("CD");
  else if (b == 500)
    printf("D");
  else if (b == 600)
    printf("DC");
  else if (b == 700)
    printf("DCC");
  else if (b == 800)
    printf("DCCC");
  else if (b == 900)
    printf("CM");
  if (c == 10)
    printf("X");
  else if (c == 20)
    printf("XX");
  else if (c == 30)
    printf("XXX");
  else if (c == 40)
    printf("XL");
  else if (c == 50)
    printf("L");
  else if (c == 60)
    printf("LX");
  else if (c == 70)
    printf("LXX");
  else if (c == 80)
    printf("LXXX");
  else if (c == 90)
    printf("XC");
  if (d == 1)
    printf("I");
  else if (d == 2)
    printf("II");
  else if (d == 3)
    printf("III");
  else if (d == 4)
    printf("IV");
  else if (d == 5)
    printf("V");
  else if (d == 6)
    printf("VI");
  else if (d == 7)
    printf("VII");
  else if (d == 8)
    printf("VIII");
  else if (d == 9)
    printf("IX");
  printf("\n");
}
int main() {
  long long a, b, i, j, m, z, p;
  char c[2], d[1000], s[1000];
  cin >> a >> c;
  cin >> d;
  if (c[0] == 'R') {
    m = 0;
    for (i = 0; i < strlen(d); i++) {
      if (d[i] >= 'A' && d[i] <= 'Z')
        m = m * a + d[i] - 55;
      else
        m = m * a + d[i] - '0';
    }
    roman(m);
  } else {
    z = 0;
    for (i = 0; i < strlen(c); i++) {
      if (c[i] >= 'A' && c[i] <= 'Z')
        z = z * 10 + c[i] - 55;
      else
        z = z * 10 + c[i] - '0';
    }
    m = 0;
    for (i = 0; i < strlen(d); i++) {
      if (d[i] >= 'A' && d[i] <= 'Z')
        m = m * a + d[i] - 55;
      else
        m = m * a + d[i] - '0';
    }
    if (m == 0) {
      cout << "0" << endl;
      return 0;
    }
    i = 0;
    while (1) {
      if (m == 0) break;
      p = m % z;
      if (p > 9)
        s[i] = p + 55;
      else
        s[i] = p + '0';
      m = m / z;
      i++;
    }
    for (j = i - 1; j >= 0; j--) {
      printf("%c", s[j]);
    }
    printf("\n");
  }
  return 0;
}
