#include <bits/stdc++.h>
using namespace std;
int getnum(char c) {
  if (c > '9') {
    return c - 'A' + 10;
  } else {
    return c - '0';
  }
}
char getchar(int val) {
  if (val < 10) {
    return val + '0';
  } else {
    return 'A' + val - 10;
  }
}
int main() {
  long long a;
  string s, sc;
  cin >> a >> s >> sc;
  vector<int> digs;
  long long b = (s == "R") ? 0 : stoll(s);
  auto idx = sc.find_first_not_of('0');
  if (idx != string::npos) {
    sc = sc.substr(idx);
  } else {
    sc = "0";
  }
  for (char c : sc) {
    digs.push_back(getnum(c));
  }
  long long num = 0;
  for (int i = 0; i < digs.size(); i++) {
    long long dig = (long long)digs[digs.size() - i - 1];
    num += pow(a, i) * dig;
  }
  if (b) {
    vector<char> outs;
    while (num > 0) {
      outs.push_back(getchar(num % b));
      num /= b;
    }
    if (outs.size() == 0) {
      cout << 0;
    } else {
      for (int i = 0; i < outs.size(); i++) {
        cout << outs[outs.size() - i - 1];
      }
    }
  } else {
    char ones[4] = {'I', 'X', 'C', 'M'};
    char fives[3] = {'V', 'L', 'D'};
    vector<char> outs;
    int place = 0;
    while (num > 0) {
      int md = num % 10;
      int df = md - 5;
      bool low = false;
      if (md < 5) {
        df = md;
        low = true;
      }
      if (md == 5) {
        outs.push_back(fives[place]);
      } else if (df == 4) {
        if (low) {
          outs.push_back(fives[place]);
          outs.push_back(ones[place]);
        } else {
          outs.push_back(ones[place + 1]);
          outs.push_back(ones[place]);
        }
      } else {
        for (int i = 0; i < df; i++) {
          outs.push_back(ones[place]);
        }
        if (!low) {
          outs.push_back(fives[place]);
        }
      }
      place++;
      num /= 10;
    }
    for (int i = 0; i < outs.size(); i++) {
      cout << outs[outs.size() - i - 1];
    }
  }
  return 0;
}
