#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
int from_digit(char c) {
  if (isdigit(c)) return c - '0';
  return tolower(c) - 'a' + 10;
}
char to_digit(int x) {
  if (x < 10) return '0' + x;
  return 'A' + x - 10;
}
long long from_base(const string& s, int base) {
  long long res = 0;
  for (int i = 0; i < s.size(); i++) res = res * base + from_digit(s[i]);
  return res;
}
string to_base(long long x, int base) {
  if (x == 0) return "0";
  string s = "";
  while (x) {
    s = to_digit(x % base) + s;
    x /= base;
  }
  return s;
}
char* rd[] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
              "XL", "X",  "IX", "V",  "IV", "I"};
int rv[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
string to_roman(int x) {
  string s;
  int p = 0;
  while (x) {
    while (rv[p] > x) p++;
    x -= rv[p];
    s += rd[p];
  }
  return s;
}
void solve() {
  int a;
  string b, s, res;
  cin >> a >> b >> s;
  long long x = from_base(s, a);
  if (b == "R")
    res = to_roman(x);
  else
    res = to_base(x, atoi(b.c_str()));
  cout << res;
}
int main() {
  solve();
  return 0;
}
