#include <bits/stdc++.h>
using namespace std;
char* toRadius(long long n, int r) {
  static char ans[1000];
  int d = 0;
  for (long long t = n; (t /= r) > 0; d++)
    ;
  ans[d + 1] = '\0';
  for (; d >= 0; d--) {
    if (n % r >= 0 && n % r <= 9) {
      ans[d] = n % r + '0';
    } else {
      ans[d] = n % r - 10 + 'A';
    }
    n /= r;
  }
  return ans;
}
char* toRoman(long long n) {
  static char ans[100];
  int pos = 0;
  if (n / 1000 > 0) {
    int t = n / 1000;
    for (int i = 0; i < t; i++) {
      ans[pos++] = 'M';
    }
    n %= 1000;
  }
  if (n / 100 > 0) {
    int t = n / 100;
    if (t <= 3) {
      for (int i = 0; i < t; i++) {
        ans[pos++] = 'C';
      }
    } else if (t == 4) {
      ans[pos++] = 'C';
      ans[pos++] = 'D';
    } else if (t >= 5 && t < 9) {
      ans[pos++] = 'D';
      for (int i = 5; i < t; i++) {
        ans[pos++] = 'C';
      }
    } else if (t == 9) {
      ans[pos++] = 'C';
      ans[pos++] = 'M';
    }
    n %= 100;
  }
  if (n / 10 > 0) {
    int t = n / 10;
    if (t <= 3) {
      for (int i = 0; i < t; i++) {
        ans[pos++] = 'X';
      }
    } else if (t == 4) {
      ans[pos++] = 'X';
      ans[pos++] = 'L';
    } else if (t >= 5 && t < 9) {
      ans[pos++] = 'L';
      for (int i = 5; i < t; i++) {
        ans[pos++] = 'X';
      }
    } else if (t == 9) {
      ans[pos++] = 'X';
      ans[pos++] = 'C';
    }
    n %= 10;
  }
  if (n > 0) {
    int t = n;
    if (t <= 3) {
      for (int i = 0; i < t; i++) {
        ans[pos++] = 'I';
      }
    } else if (t == 4) {
      ans[pos++] = 'I';
      ans[pos++] = 'V';
    } else if (t >= 5 && t < 9) {
      ans[pos++] = 'V';
      for (int i = 5; i < t; i++) {
        ans[pos++] = 'I';
      }
    } else if (t == 9) {
      ans[pos++] = 'I';
      ans[pos++] = 'X';
    }
    n %= 10;
  }
  ans[pos] = '\0';
  return ans;
}
long long rtol(char* str, int r) {
  long long ans = 0;
  while ((*str) != '\0') {
    ans *= r;
    char c = *str;
    if (isdigit(c)) {
      ans += c - '0';
    } else {
      ans += c - 'A' + 10;
    }
    str++;
  }
  return ans;
}
int main() {
  long long n;
  int a;
  char rr[4];
  char nn[50000];
  cin >> a >> rr;
  cin >> nn;
  n = rtol(nn, a);
  if (rr[0] == 'R') {
    cout << toRoman(n) << endl;
  } else {
    cout << toRadius(n, atoi(rr)) << endl;
  }
  return 0;
}
