import sys rom_dic = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000} n = input() rom_nums = input().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 = {0: "", 1: "I", 2: "II", 3: "III", 4: "IV", 9:"IX"} rom_sum = [] trans = ["IVX", "XLC", "CDM", "M "] while s: s, d = divmod(s, 10) r = d2r[d] if d < 5 else "V" + d2r[d - 5] if d < 9 else "IX" rom_sum.append(r.translate(str.maketrans("IVX", trans.pop(0)))) print("".join(reversed(rom_sum)))