
#include <string.h>

#define MAX_LENGTH 5

char roman[4][10][MAX_LENGTH] =
{
    "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX",
    "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC",
    "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM",
    "", "M", "MM", "MMM", "  ", " ", "  ", "   ", "    ", "  "
};

void IntegerToRoman(int n, char* s)
{
    strcpy(s,"");
    if (n>3999 || n<1)return;
    
    int digit = 1;
    int m = 1;
    while((m*=10) <= n)++digit;
    
    while((m/=10)>0)
    {
        strcat(s,roman[--digit][n/m]);
        n %= m;
    }
}


#include <stdio.h>

using namespace std;

int main(int argc, char** argv)
{
    int n;
    char r[256];
    
    while(scanf("%d", &n)>0)
    {
        IntegerToRoman(n, r);
        printf("%s\n", r);
    }

    return 0;
}