#include <bits/stdc++.h>
int64_t decode(char c) {
  if (isdigit(c)) {
    return c - '0';
  }
  return 10 + toupper(c) - 'A';
}
char encode(int64_t d) {
  if (d < 10) {
    return d + '0';
  }
  return d - 10 + 'A';
}
void roman(int64_t base, const std::string& s) {
  int64_t x = 0;
  for (char c : s) {
    x = x * base + decode(c);
  }
  const std::map<int64_t, std::string> map = {
      {1, "I"},   {4, "IV"},   {5, "V"},    {9, "IX"},  {10, "X"},
      {40, "XL"}, {50, "L"},   {90, "XC"},  {100, "C"}, {400, "CD"},
      {500, "D"}, {900, "CM"}, {1000, "M"},
  };
  while (x != 0) {
    const auto& it = std::prev(map.upper_bound(x));
    x -= it->first;
    std::cout << it->second;
  }
  std::cout << '\n';
}
void base(int64_t a, int64_t b, const std::string& s) {
  int64_t x = 0;
  for (char c : s) {
    x = x * a + decode(c);
  }
  std::string result;
  while (x != 0) {
    result += encode(x % b);
    x /= b;
  }
  if (result.empty()) {
    result.push_back('0');
  }
  std::reverse(result.begin(), result.end());
  std::cout << result << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int64_t a;
  std::string b;
  std::cin >> a >> b;
  std::string c;
  std::cin >> c;
  if (b[0] == 'R') {
    roman(a, c);
  } else {
    base(a, std::stol(b), c);
  }
}
