N = int(input()) lsR = input().split() d1 = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000} d2 = {'IV':4,'IX':9,'XL':40,'XC':90,'CD':400,'CM':900} ans = 0 for i in range(N): r = lsR[i] n = len(r) now = 0 v = 0 while now < n: if now == n-1: v += d1[r[now]] now += 1 continue if r[now]+r[now+1] in d2: v += d2[r[now]+r[now+1]] now += 2 else: v += d1[r[now]] now += 1 ans += v if ans >= 4000: print('ERROR') exit() dall = [] for key,val in d1.items(): dall.append((val,key)) for key,val in d2.items(): dall.append((val,key)) dall.sort() ans2 = '' while ans != 0: v,k = dall[-1] if ans >= v: ans2 += k ans -= v else: dall.pop() print(ans2)