#include <bits/stdc++.h>
const char word[] = "IVXLCDM";
const int list[] = {1, 5, 10, 50, 100, 500, 1000};
long long Exchange10(char *word, int base) {
  long long result = 0;
  for (char *ptr = word; *ptr; ++ptr) {
    result *= base;
    if (isalpha(*ptr))
      result += *ptr - 'A' + 10;
    else
      result += *ptr - '0';
  }
  return result;
}
void ChangeBase(long long num, int b) {
  if (num == 0) return;
  ChangeBase(num / b, b);
  if (num % b >= 10)
    printf("%c", (char)(num % b - 10 + 'A'));
  else
    printf("%d", (int)(num % b));
}
void ChangeRoman(int num) {
  for (int i = 1000, j = 6; i > 0; i /= 10, j -= 2) {
    int digit = num / i % 10;
    if (digit == 9)
      printf("%c%c", word[j], word[j + 2]);
    else if (digit == 4)
      printf("%c%c", word[j], word[j + 1]);
    else {
      if (digit >= 5) {
        printf("%c", word[j + 1]);
        digit -= 5;
      }
      for (int k = 0; k < digit; ++k) printf("%c", word[j]);
    }
  }
}
int main() {
  char line[1000 + 1];
  int a, b;
  scanf("%d%s", &a, line);
  if (line[0] == 'R')
    b = 0;
  else
    sscanf(line, "%d", &b);
  scanf("%s", line);
  long long num = Exchange10(line, a);
  if (b == 0)
    ChangeRoman(num);
  else {
    if (num == 0)
      printf("0");
    else
      ChangeBase(num, b);
  }
  puts("");
  return 0;
}
