#include <bits/stdc++.h>
using namespace std;
map<int, string> ma;
long long change(string a, long long base) {
  long long ans = 0;
  int len = a.length();
  long long t = 1;
  for (int i = len - 1; i >= 0; i--) {
    if (a[i] >= 'A' && a[i] <= 'Z') {
      ans += (a[i] - 'A' + 10) * t;
    } else
      ans += (a[i] - '0') * t;
    t *= base;
  }
  return ans;
}
int convert(string a) {
  int ans = 0;
  for (int i = 0; i < a.length(); i++) {
    ans = ans * 10 + (a[i] - '0');
  }
  return ans;
}
string changex(long long a, int base) {
  string ans;
  while (a) {
    long long res = a % base;
    if (res >= 10)
      ans += res - 10 + 'A';
    else
      ans += res + '0';
    a /= base;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
string work(string c) {
  string ans;
  int index = 0;
  while (c[index] == '0') {
    index++;
    if (index == c.length()) {
      ans = "0";
      return ans;
    }
  }
  for (int i = index; i < c.length(); i++) {
    ans += c[i];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ma[900] = "CM", ma[400] = "CD", ma[90] = "XC", ma[40] = "XL", ma[9] = "IX",
  ma[4] = "IV";
  int a;
  string b;
  cin >> a >> b;
  string c;
  cin >> c;
  c = work(c);
  if (c == "0") {
    cout << 0 << '\n';
    return 0;
  }
  long long num = change(c, a);
  if (b == "R") {
    string ans;
    string lead;
    while (num) {
      if (num >= 1000) {
        ans += "M";
        num -= 1000;
      } else if (num >= 500) {
        if (num >= 900) {
          ans += ma[900];
          num -= 900;
          continue;
        }
        ans += "D";
        num -= 500;
      } else if (num >= 100) {
        if (num >= 400) {
          ans += ma[500];
          num -= 400;
          continue;
        }
        ans += "C";
        num -= 100;
      } else if (num >= 50) {
        if (num >= 90) {
          ans += ma[90];
          num -= 90;
          continue;
        }
        ans += "L";
        num -= 50;
      } else if (num >= 10) {
        if (num >= 40) {
          ans += ma[40];
          num -= 40;
          continue;
        }
        ans += "X";
        num -= 10;
      } else if (num >= 5) {
        if (num == 9) {
          ans += ma[9];
          break;
        }
        ans += "V";
        num -= 5;
      } else {
        if (num == 4) {
          ans += ma[4];
          break;
        }
        ans += "I";
        num--;
      }
    }
    cout << ans << '\n';
  } else {
    int z = convert(b);
    cout << changex(num, z) << '\n';
  }
  return 0;
}
