#include <bits/stdc++.h>   using namespace std;   const string roman[] = { M ,   CM ,  D ,   CD ,  C ,   XC ,  L ,                            XL ,  X ,   IX ,  V ,   IV ,  I };   const int roman_num[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};   int a;   string b, c;   string ans;   long long toint(string s, int base) {     long long res = 0, add;     for (int i = 0; i < s.size(); i++) {       res = res * base;       if (isdigit(s[i]))         add = s[i] -  0 ;       else         add = s[i] -  A  + 10;       res += add;     }     return res;   }   string roman_convert(int num) {     int pos = 0;     string res =   ;     while (num > 0) {       while (roman_num[pos] <= num) {         num -= roman_num[pos];         res += roman[pos];       }       pos++;     }     return res;   }   string convert(string c, int from, int to) {     long long base_10 = 0LL;     string temp = c;     for (int i = 0; i < temp.size(); i++) {       int add;       if (isdigit(temp[i]))         add = temp[i] -  0 ;       else         add = temp[i] -  A  + 10;       base_10 = base_10 * from + add;     }     string res =   ;     while (base_10) {       int digit = base_10 % to;       if (digit >= 10)         res.push_back( A  + digit - 10);       else         res.push_back(digit +  0 );       base_10 /= to;     }     if (res.empty()) return  0 ;     reverse(res.begin(), res.end());     while (res.at(0) ==  0  && res.size() > 11) res.erase(0, 1);     return res;   }   int main() {     cin.sync_with_stdio(0);     cin >> a >> b >> c;     while (c[0] ==  0  && c.size() > 1) c.erase(0, 1);     if (b ==  R ) {       int temp = toint(c, a);       ans = roman_convert(temp);     } else {       int base = toint(b, 10);       ans = convert(c, a, base);     }     puts(ans.c_str());     return 0;   }   