import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys import time from collections import Counter,deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush_max(heap,item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappushpop_max(heap, item): if heap and item < heap[0]: item, heap[0] = heap[0], item heapq._siftup_max(heap, 0) return item from math import gcd as GCD read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines write=sys.stdout.write N=int(readline()) num=0 for R in readline().split(): while R: if len(R)>=2 and R[:2] in ("IV","IX","XL","XC","CD","CM"): if R[:2]=="IV": num+=4 elif R[:2]=="IX": num+=9 elif R[:2]=="XL": num+=40 elif R[:2]=="XC": num+=90 elif R[:2]=="CD": num+=400 elif R[:2]=="CM": num+=900 R=R[2:] else: for i in range(len(R)): if R[0]!=R[i]: break else: i=len(R) if R[0]=="M": num+=1000*i elif R[0]=="D": num+=500*i elif R[0]=="C": num+=100*i elif R[0]=="L": num+=50*i elif R[0]=="X": num+=10*i elif R[0]=="V": num+=5*i elif R[0]=="I": num+=i R=R[i:] ans_lst=[] if num>=4000: ans_lst.append("ERROR") else: x=num//1000 num%=1000 if x: ans_lst.append("M"*x) x=num//100 num%=100 if x==9: ans_lst.append("CM") elif 5<=x<=8: ans_lst.append("D"+"C"*(x-5)) elif x==4: ans_lst.append("CD") elif x: ans_lst.append("C"*x) x=num//10 num%=10 if x==9: ans_lst.append("XC") elif 5<=x<=8: ans_lst.append("L"+"X"*(x-5)) elif x==4: ans_lst.append("XL") elif x: ans_lst.append("X"*x) x=num if x==9: ans_lst.append("IX") elif 5<=x<=8: ans_lst.append("V"+"I"*(x-5)) elif x==4: ans_lst.append("IV") elif x: ans_lst.append("I"*x) print(*ans_lst,sep="")