#include <bits/stdc++.h>
using namespace std;
char inp[2000];
int toNum(char x) {
  if (x >= '0' && x <= '9') return x - '0';
  return 10 + x - 'A';
}
char toChar(int x) {
  if (x < 10) return '0' + x;
  return 'A' + (x - 10);
}
long long ato10(int a) {
  int len = strlen(inp);
  int lw = 0;
  while (lw < len && inp[lw] == '0') lw++;
  if (lw >= len) return 0;
  long long ret = 0;
  for (int i = lw; i < len; i++) {
    ret = ret * a + toNum(inp[i]);
  }
  return ret;
}
char pI[] = {'I', 'X', 'C', 'M'};
char pV[] = {'V', 'L', 'D'};
int main() {
  int a, b;
  gets(inp);
  bool iR = false;
  int len = strlen(inp);
  for (int i = 0; i < len; i++) {
    if (inp[i] == 'R') iR = true;
  }
  if (!iR)
    sscanf(inp, "%d%d", &a, &b);
  else
    sscanf(inp, "%d", &a);
  gets(inp);
  long long number = ato10(a);
  if (!iR) {
    string ret = "";
    if (number == 0)
      ret = "0";
    else {
      while (number) {
        ret = toChar(number % b) + ret;
        number /= b;
      }
    }
    printf("%s\n", ret.c_str());
  } else {
    int idx = 0;
    string ret = "";
    while (number) {
      int tdec = number % 10;
      number /= 10;
      if (tdec <= 3)
        for (int t = 0; t < tdec; t++) ret = pI[idx] + ret;
      else if (tdec == 4) {
        ret = pV[idx] + ret;
        ret = pI[idx] + ret;
      } else if (tdec == 5)
        ret = pV[idx] + ret;
      else if (tdec <= 8) {
        tdec -= 5;
        for (int t = 0; t < tdec; t++) ret = pI[idx] + ret;
        ret = pV[idx] + ret;
      } else {
        ret = pI[idx + 1] + ret;
        ret = pI[idx] + ret;
      }
      idx++;
    }
    printf("%s\n", ret.c_str());
  }
  return 0;
}
