#include <bits/stdc++.h>
using namespace std;
int getNum(char c) {
  if (isdigit(c)) return c - '0';
  return c - 'A' + 10;
}
char putNum(int i) {
  if (i < 10) return i + '0';
  return 'A' + i - 10;
}
long long decode(int a, string c) {
  long long res = 0;
  for (int i = 0; i < c.size(); i++) {
    res = res * a + getNum(c[i]);
  }
  return res;
}
string roman(string b, long long c) {
  char o[4] = {'M', 'C', 'X', 'I'};
  char f[4] = {'?', 'D', 'L', 'V'};
  string res;
  int div[4] = {1000, 100, 10, 1};
  for (int i = 0; i < 4; i++) {
    int cur = (c / div[i]) % 10;
    if (cur == 0) continue;
    if (1 <= cur && cur <= 3) {
      for (int j = 0; j < cur; j++) res += o[i];
    }
    if (cur == 4) {
      res += o[i];
      res += f[i];
    }
    if (5 <= cur && cur <= 8) {
      res += f[i];
      for (int j = 0; j < cur - 5; j++) res += o[i];
    }
    if (cur == 9) {
      res += o[i];
      res += o[i - 1];
    }
  }
  return res;
}
string encode(string b, long long c) {
  if (b == "R") {
    return roman(b, c);
  }
  int base = 0;
  for (int i = 0; i < b.size(); i++) base = 10 * base + b[i] - '0';
  string res;
  while (c) {
    res = putNum(c % base) + res;
    c /= base;
  }
  return res;
}
int main() {
  int a;
  string b, c;
  while (cin >> a >> b >> c) {
    long long L = decode(a, c);
    if (L == 0)
      cout << 0 << endl;
    else
      cout << encode(b, L) << endl;
  }
}
