#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:16000000")
#pragma warning(disable : 4996)
const int inf = 1 << 25;
const double eps = 1e-9;
int todigit(char c) { return isdigit(c) ? c - '0' : c - 'A' + 10; }
char tochar(int x) { return x < 10 ? x + '0' : x - 10 + 'A'; }
string conv(long long x, int base) {
  string ret;
  do {
    ret += tochar(x % base);
    x /= base;
  } while (x > 0);
  reverse(ret.begin(), ret.end());
  return ret;
}
string rc = "IVXLCDM";
int values[] = {1, 5, 10, 50, 100, 500, 1000};
string rome(long long x) {
  if (x == 0) return "";
  if (x == 1) return "I";
  int lb = lower_bound(values, values + 7, x) - values;
  if (lb == 7 || x < values[lb]) --lb;
  if (x >= 4 * values[lb]) {
    return string(1, rc[lb]) + rc[lb + 1] + rome(x % values[lb]);
  }
  if (lb > 0 && lb < 6 && x >= values[lb + 1] - values[lb - 1]) {
    return string(1, rc[lb - 1]) + rc[lb + 1] + rome(x % values[lb - 1]);
  } else {
    return string(1, rc[lb]) + rome(x - values[lb]);
  }
}
int main() {
  int a;
  string b, c;
  cin >> a >> b >> c;
  long long x = 0;
  for (int i = (0); i < ((int)c.size()); ++i) x = x * a + todigit(c[i]);
  if (b[0] == 'R')
    cout << rome(x) << endl;
  else
    cout << conv(x, atoi(b.c_str())) << endl;
  return 0;
}
