#include <bits/stdc++.h>
using namespace std;
long long power(long long k, long long n, long long m = 1e18 + 7) {
  long long res = 1;
  while (n) {
    if (n % 2 != 0) {
      res = (res * k) % m;
    }
    k = (k * k) % m;
    n = n / 2;
  }
  return (res);
}
void roman(long long number) {
  int sys[] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
  string str[] = {"I",  "IV", "V",  "IX", "X",  "XL", "L",
                  "XC", "C",  "CD", "D",  "CM", "M"};
  int i = 12;
  while (number > 0) {
    int div = number / sys[i];
    number = number % sys[i];
    while (div--) {
      cout << str[i];
    }
    i--;
  }
}
void radix_b(long long number, long long base) {
  long long a, c, i;
  string str = "";
  while (number > 0) {
    a = number % base;
    if (a >= 10) {
      a = a + 55;
    } else {
      a = a + 48;
    }
    char ch = a;
    str = str + ch;
    number /= base;
  }
  for (i = str.size() - 1; i >= 0; i = i - 1) {
    cout << str[i];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b, i, j, n, c, d, k, t, m, q, x, y, f;
  string str, str1;
  char ch;
  cin >> a >> str1 >> str;
  d = 0;
  f = count(str.begin(), str.end(), '0');
  if (f == str.size()) {
    cout << "0";
    exit(0);
  }
  for (i = str.size() - 1; i >= 0; i = i - 1) {
    char chr = str[i];
    b = chr;
    if (b >= 65) {
      b = b - 55;
    } else {
      b = b - 48;
    }
    d = d + b * power(a, str.size() - 1 - i);
  }
  if (str1 == "R") {
    roman(d);
  } else {
    stringstream temp;
    temp << str1;
    temp >> b;
    radix_b(d, b);
  }
}
