#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    map<string,int> mp = {
        {"I",    1},
        {"V",    5},
        {"X",   10},
        {"L",   50},
        {"C",  100},
        {"D",  500},
        {"M", 1000},
        {"IV",    5 -   1},
        {"IX",   10 -   1},
        {"XL",   50 -  10},
        {"XC",  100 -  10},
        {"CD",  500 - 100},
        {"CM", 1000 - 100}
    };
    map<int,string> inv;
    for(auto [s, n] : mp) inv[-n] = s;

    int N; cin >> N;
    int sumR = 0;
    rep(i,N) {
        string s; cin >> s;
        vector<int> a;
        for(char c : s) a.push_back(mp[string(1, c)]);
        rep(i,a.size()-1) if(a[i] < a[i + 1]) a[i] *= -1;
        sumR += accumulate(a.begin(), a.end(), 0);
    }

    if(sumR > 3999) {
        cout << "ERROR" << endl;
    } else {
        string ans = "";
        for(auto [n, s] : inv) {
            int x = -n;
            rep(_,sumR/x) ans += s;
            sumR %= x;
        }
        cout << ans << endl;
    }
}