#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

class romanNumerals
{
private:
    static const string ROMAN_CHAR;
public:
    static string toStr(int a){
        if(!(0 < a && a < 4000))
            return "";

        string ans;
        for(int i=0; i<4; ++i){
            int x = a % 10;
            a /= 10;
            if(x == 9){
                ans += ROMAN_CHAR[2*i+2];
                ans += ROMAN_CHAR[2*i];
            }
            else if(x == 4){
                ans += ROMAN_CHAR[2*i+1];
                ans += ROMAN_CHAR[2*i];
            }
            else{
                ans += string(x % 5, ROMAN_CHAR[2*i]);
                ans += string(x / 5, ROMAN_CHAR[2*i+1]);
            }
        }
        reverse(ans.begin(), ans.end());
        return ans;
    }
    static int toInt(const string& s){
        int n = s.size();
        int k = 0;
        int ans = 0;

        for(int i=3; i>=0; --i){
            ans *= 10;
            if(k < n - 1 && s[k] == ROMAN_CHAR[2*i] && s[k+1] == ROMAN_CHAR[2*i+2]){
                ans += 9;
                k += 2;
            }
            else if(k < n - 1 && s[k] == ROMAN_CHAR[2*i] && s[k+1] == ROMAN_CHAR[2*i+1]){
                ans += 4;
                k += 2;
            }
            else{
                if(k < n && s[k] == ROMAN_CHAR[2*i+1]){
                    ans += 5;
                    ++ k;
                }
                int len = 0;
                while(k < n && s[k] == ROMAN_CHAR[2*i]){
                    ++ ans;
                    ++ k;
                    ++ len;
                }
                if(len > 3)
                    return 0;
            }
        }

        if(k < n)
            return 0;
        else
            return ans;
    }
};
const string romanNumerals::ROMAN_CHAR = "IVXLCDM__";

int main()
{
    int n;
    cin >> n;

    int sum = 0;
    for(int i=0; i<n; ++i){
        string s;
        cin >> s;
        sum += romanNumerals::toInt(s);
    }

    string ans = romanNumerals::toStr(sum);
    if(ans.empty())
        cout << "ERROR" << endl;
    else
        cout << ans << endl;

    return 0;
}