#include using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) template bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; int N; map mp{{'I',1},{'V',5},{'X',10},{'L',50},{'C',100},{'D',500},{'M',1000}}; int A [] = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; string B [] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; string toRoma(int val) { string res; FOR(i,0,13){ while(val >= A [i]){ res += B [i]; val -= A [i]; } } return res; } int fromRoma(string str) { int n = str.size(); int res = 0; FOR(i,0,n){ if(i == n - 1 || mp [str [i]] >= mp [str [i + 1]]){ res += mp [str [i]]; } else{ res -= mp [str [i]]; } } return res; } int main() { scanf("%d",&N); int sum = 0; FOR(i,0,N){ string S; cin >> S; sum += fromRoma(S); } if(sum >= 4000){ puts("ERROR"); } else{ printf("%s\n",toRoma(sum).c_str()); } return 0; }