using System.Collections.Generic;
using System;

public class Hello
{
    public static Dictionary<string, int> d, d2;
    public static Dictionary<int ,string > d3, d4;
    static void Main()
    {
        var a = new string[] { "I", "V", "X", "L", "C", "D", "M" };
        var a2 = new int[] { 1, 5, 10, 50, 100, 500, 1000 };
        var b = new string[] { "IV", "IX", "XL", "XC", "CD", "CM" };
        var b2 = new int[] { 4, 9, 40, 90, 400, 900 };
        d = new Dictionary<string, int>();
        d2 = new Dictionary<string, int>();
        d3 = new Dictionary<int, string>();
        d4 = new Dictionary<int, string>();
        for (int i = 0; i < a.Length; i++) { d[a[i]] = a2[i]; d3[a2[i]] = a[i]; }
        for (int i = 0; i < b.Length; i++) { d2[b[i]] = b2[i]; d4[b2[i]] = b[i]; }
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var sum = 0;
        foreach (var x in line) sum += calc(x);
        getAns(sum);

    }
    static int calc(string s)
    {
        var res = 0;
        foreach (var x in d2)
        {
            var sL = s.Length;
            s = s.Replace(x.Key, "");
            var sL2 = s.Length;
            res += (sL - sL2) / 2 * x.Value;
        }
        foreach (var x in s) res += d[x.ToString()];
        return res;
    }
    static void getAns(int t)
    {
        if (t > 3999) { Console.WriteLine("ERROR"); return; }
        var s = "";
        var a = t / 1000;
        s += new string('M', a);
        t %= 1000;
        var b = t / 100;
        if (b == 9) s += d4[900];
        else if (b >= 5) s += d3[500] + new string('C', b % 5);
        else if (b == 4) s += d4[400];
        else s += new string('C', b);
        t %= 100;
        var c = t / 10;
        if (c == 9) s += d4[90];
        else if (c >= 5) s += d3[50] + new string('X', c % 5);
        else if (c == 4) s += d4[40];
        else s += new string('X', c);
        t %= 10;
        if (t == 9) s += d4[9];
        else if (t >= 5) s += d3[5] + new string('I', t % 5);
        else if (t == 4) s += d4[4];
        else s += new string('I', t);
        Console.WriteLine(s);
    }
}