#include <bits/stdc++.h>
using namespace std;
int v(char c) {
  if (c >= '0' && c <= '9')
    return (c - '0');
  else
    return (c - 'A') + 10;
}
char rv(int c) {
  if (c >= 0 && c <= 9)
    return (c + '0');
  else
    return ((c - 10) + 'A');
}
long long pr(int b, int p) {
  long long ret = 1;
  for (int(i) = (0); (i) < (p); (i)++) {
    ret = (ret * (long long)b);
  }
  return ret;
}
long long tod(string now, int b) {
  int l = now.size();
  long long ret = 0;
  for (int(i) = (0); (i) < (l); (i)++) {
    ret += (v(now[i]) * pr(b, l - i - 1));
  }
  return ret;
}
char *changeRom(long long nowP) {
  struct RomStruct {
    char *ovsStr;
    long long ovsInt;
  };
  static const RomStruct RDigi[] = {
      {"M", 1000}, {"CM", 900}, {"D", 500}, {"CD", 400}, {"C", 100},
      {"XC", 90},  {"L", 50},   {"XL", 40}, {"X", 10},   {"IX", 9},
      {"V", 5},    {"IV", 4},   {"I", 1},
  };
  static char ret_rom[55];
  ret_rom[0] = '\0';
  int olls = 0;
  for (int i = 0; nowP && i < sizeof(RDigi) / sizeof(RDigi[0]); i++) {
    while (RDigi[i].ovsInt <= nowP) {
      strcat(ret_rom, RDigi[i].ovsStr);
      nowP -= RDigi[i].ovsInt;
    }
  }
  return ret_rom;
}
string revb(long long d, int b) {
  string ret = "";
  int os;
  while (d != 0) {
    os = (d % b);
    ret += rv(os);
    d /= b;
  }
  if (ret == "") ret = "0";
  reverse((ret).begin(), (ret).end());
  return ret;
}
int main() {
  int a;
  string c, b, res;
  while (cin >> a >> b) {
    cin >> c;
    long long dv = tod(c, a);
    if (b.size() == 1 && b[0] == 'R') {
      res = changeRom(dv);
    } else {
      int bss;
      sscanf(b.c_str(), "%d", &bss);
      res = revb(dv, bss);
    }
    cout << res << endl;
  }
  return 0;
}
