n = int(input()) dic = {"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000} lst = ["M","D","C","L","X","V","I"] num = list(input().split()) ans = 0 kaito = "" for i in num: tmp = [dic[i[0]]] for index in range(1,len(i)): x = dic[i[index]] if tmp[-1]3999: print("ERROR") exit(0) for i,s in enumerate(lst): x = dic[s] y = ans//x if y==4: kaito += lst[i] + lst[i-1] elif y>0: kaito += lst[i]*y ans -= x*y print(kaito)