#include <bits/stdc++.h>
using namespace std;
string base;
string r1[] = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
string r2[] = {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
string r3[] = {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
string r4[] = {"M", "MM", "MMM"};
int find_num(char ch) {
  for (int i = 0; i < base.size(); i++)
    if (base[i] == ch) return i;
}
string dectox(long long p, int osn) {
  string s;
  do {
    s.push_back(base[p % osn]);
    p /= osn;
  } while (p);
  reverse(s.begin(), s.end());
  return s;
}
long long xtodec(string &s, int osn) {
  long long ans = 0;
  while (s.size() > 1 && s[0] - '0' == 0) s.erase(s.begin());
  reverse(s.begin(), s.end());
  for (int i = 0; i < s.size(); i++)
    ans += (long long)pow((double)osn, (double)i) * (long long)(find_num(s[i]));
  return ans;
}
string dectorome(long long p) {
  string s;
  while (p) {
    if (p < 10) {
      s += (r1[p - 1]);
      p = 0;
    } else if (p < 100) {
      s += (r2[p / 10 - 1]);
      p %= 10;
    } else if (p < 1000) {
      s += (r3[p / 100 - 1]);
      p %= 100;
    } else {
      s += (r4[p / 1000 - 1]);
      p %= 1000;
    }
  }
  return s;
}
void init() {
  for (int i = 0; i < 10; i++) base.push_back(i + '0');
  char ch = 'A';
  while (base.size() < 27) {
    base.push_back(ch++);
  }
}
int main() {
  init();
  string s;
  int a, b;
  cin >> a;
  cin >> s;
  if (!isdigit(s[0])) {
    cin >> s;
    cout << dectorome(xtodec(s, a));
  } else {
    b = atoi(s.c_str());
    cin >> s;
    cout << dectox(xtodec(s, a), b);
  }
  return 0;
}
