#include <bits/stdc++.h>
using namespace std;
inline int tonum(char ch) {
  if (ch >= '0' && ch <= '9')
    return ch - '0';
  else
    return ch - 'A' + 10;
}
inline char toch(int num) {
  if (num >= 0 && num <= 9) return num + '0';
  return num - 10 + 'A';
}
int change(long long c, int base, int *num) {
  int x = 0;
  do {
    num[x++] = c % base;
    c /= base;
  } while (c);
  return x;
}
int table[100] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
char table2[100][10] = {"I",  "IV", "V",  "IX", "X",  "XL", "L",
                        "XC", "C",  "CD", "D",  "CM", "M"};
int main() {
  int a;
  char str[10];
  long long c;
  char num[10000];
  scanf("%d%s", &a, str);
  scanf("%s", num);
  c = 0;
  for (int i = 0; num[i]; i++) {
    c = c * a + tonum(num[i]);
  }
  if (str[0] == 'R') {
    char ans[100000];
    strcpy(ans, "");
    for (int i = 12; i >= 0; i--) {
      while (c >= table[i]) {
        c -= table[i];
        strcat(ans, table2[i]);
      }
    }
    printf("%s\n", ans);
  } else {
    int b = 0;
    for (int i = 0; str[i]; i++) {
      b = b * 10 + str[i] - '0';
    }
    int temp[100000];
    int ret = change(c, b, temp);
    for (int i = ret - 1; i >= 0; i--) {
      printf("%c", toch(temp[i]));
    }
    printf("\n");
  }
  return 0;
}
