#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;
const ll inf = 1e18 + 100;
const ll mod = 998244353;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int kc[] = {-2, -2, -1, 1, 2, 2, -1, 1};
int dgr[] = {-1, -1, 1, 1};
int dgc[] = {1, -1, -1, 1};
const int N = 100;
char cnt[N];
void numeric() {
  for (int i = 0; i < 10; i++) {
    cnt[i] = i + '0';
  }
  for (int i = 10; i <= 30; i++) {
    cnt[i] = i - 10 + 'A';
  }
}
int value(char ch) {
  if (isdigit(ch)) return ch - '0';
  return ch - 'A' + 10;
}
ll decimel(string str, int b) {
  ll ans = 0, cur = 1;
  for (int i = str.size() - 1; i >= 0; i--) {
    ans += (value(str[i]) * cur);
    cur *= b;
  }
  return ans;
}
string wish(ll x, int b) {
  string ans;
  while (x) {
    ans += (cnt[x % b]);
    x /= b;
  }
  reverse(begin(ans), end(ans));
  return ans;
}
vector<int> tmp;
string roman(ll x) {
  tmp.push_back(1);
  tmp.push_back(4);
  tmp.push_back(5);
  tmp.push_back(9);
  tmp.push_back(10);
  tmp.push_back(40);
  tmp.push_back(50);
  tmp.push_back(90);
  tmp.push_back(100);
  tmp.push_back(400);
  tmp.push_back(500);
  tmp.push_back(900);
  tmp.push_back(1000);
  string st[1111];
  st[1] = "I";
  st[4] = "IV";
  st[5] = "V";
  st[9] = "IX";
  st[10] = "X";
  st[50] = "L";
  st[100] = "C";
  st[500] = "D";
  st[1000] = "M";
  st[40] = "XL";
  st[90] = "XC";
  st[400] = "CD";
  st[900] = "CM";
  string ans;
  while (x) {
    int cur = 1;
    for (int val : tmp) {
      if (x >= val) {
        cur = val;
      } else {
        break;
      }
    }
    for (int i = 1; i * cur <= x; i++) {
      ans += st[cur];
    }
    x = x % cur;
  }
  return ans;
}
void solve() {
  int a, b;
  string str;
  string c;
  cin >> a >> str >> c;
  ll give = decimel(c, a);
  string ans;
  if (give == 0) {
    cout << 0 << "\n";
    return;
  }
  if (str[0] != 'R') {
    b = stoi(str);
    ans = wish(give, b);
  } else {
    ans = roman(give);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tt = 1;
  numeric();
  while (tt--) {
    solve();
  }
  return 0;
}
