import sys rom_dic = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000} n = sys.stdin.readline() rom_nums = sys.stdin.readline().split() s = 0 for rom_num in rom_nums: ara_num = [rom_dic[x] for x in rom_num] s += ara_num[-1] for a, b in zip(ara_num[:-1], ara_num[1:]): s += -a if a < b else a if s > 3999: print("ERROR") sys.exit(0) d2r = {5:"V", 10:"X"} rom_sum = [] trans = ["IVX", "XLC", "CDM", "M "] while s: s, d = divmod(s, 10) r = "I" * d if d < 4 else "V" + "I" * (d - 5) if 4 < d < 9 else "I" + d2r[d + 1] rom_sum.append(r.translate(str.maketrans("IVX", trans.pop(0)))) print("".join(reversed(rom_sum)))