#include <bits/stdc++.h>
unsigned long long toDen(int base, char *k) {
  unsigned long long n = 0, exp = 1;
  int i, len = strlen(k);
  for (i = len - 1; i >= 0; i--) {
    if (isdigit(k[i]))
      n += exp * (k[i] - '0');
    else
      n += exp * (k[i] - 'A' + 10);
    exp *= base;
  }
  return n;
}
void toRoman(unsigned long long k) {
  int num[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
  char str[13][3] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                     "XL", "X",  "IX", "V",  "IV", "I"};
  int i;
  for (i = 0; i < 13; ++i) {
    while (k >= num[i]) {
      printf("%s", str[i]);
      k -= num[i];
    }
  }
  puts("");
}
void toBase(int base, unsigned long long k) {
  int i = 0;
  char tmp[100], ans[100];
  memset(tmp, 0, sizeof(tmp));
  while (k >= base) {
    int r = k % base;
    tmp[i] = r > 9 ? (r + 'A' - 10) : (r + '0');
    k /= base;
    i++;
  }
  if (k >= 0) tmp[i] = k > 9 ? (k + 'A' - 10) : (k + '0');
  int len = strlen(tmp);
  for (i = 0; i < len; ++i) {
    putchar(tmp[len - i - 1]);
  }
  puts("");
}
int main() {
  int a;
  unsigned long long c;
  char inb[5], inc[1010], out[100];
  scanf("%d %s %s", &a, inb, inc);
  c = toDen(a, inc);
  if (inb[0] == 'R')
    toRoman(c);
  else {
    int b;
    sscanf(inb, "%d", &b);
    toBase(b, c);
  }
  return 0;
}
