#include <bits/stdc++.h>
using namespace std;
map<int, string> mp;
long long tobase10(string c, int b) {
  long long num = 0, p = 1;
  for (int i = c.size() - 1; i >= 0; --i) {
    int digito = (c[i] >= '0' and c[i] <= '9' ? c[i] - '0' : c[i] - 'A' + 10);
    num += (digito * p);
    p *= b;
  }
  return num;
}
void to_base(long long num, long long base) {
  vector<int> n;
  while (num > 0) {
    n.push_back(num % base);
    num /= base;
  }
  for (int i = n.size() - 1; i >= 0; --i) {
    if (n[i] < 10)
      cout << n[i];
    else
      cout << (char)(n[i] + 'A' - 10);
  }
  if (n.size() == 0) cout << 0;
}
string get(int num) {
  string ans = "";
  while (num > 0) {
    auto id = mp.upper_bound(num);
    id--;
    ans += id->second;
    num -= id->first;
  }
  return ans;
}
void to_roman(long long num) {
  int p = 1;
  string ans = "";
  while (num > 0) {
    int last = (num % 10) * p;
    ans = get(last) + ans;
    num /= 10;
    p *= 10;
  }
  cout << ans;
}
int main() {
  mp[1] = "I";
  mp[4] = "IV";
  mp[5] = "V";
  mp[9] = "IX";
  mp[10] = "X";
  mp[40] = "XL";
  mp[50] = "L";
  mp[90] = "XC";
  mp[100] = "C";
  mp[400] = "CD";
  mp[500] = "D";
  mp[900] = "CM";
  mp[1000] = "M";
  string b, c;
  long long a;
  cin >> a >> b >> c;
  long long numero_a = tobase10(c, a);
  if (b == "R")
    to_roman(numero_a);
  else
    to_base(numero_a, stoi(b));
  return 0;
}
