input() rn = input().strip().split() table = { "I": ({"V": 4, "X": 9 }, 1), "V": ({}, 5), "X": ({"L": 40, "C": 90 }, 10), "L": ({}, 50), "C": ({"D": 400, "M": 900 }, 100), "D": ({}, 500), "M": ({}, 1000), } total = 0 for r in rn: r += "$" i = 0 while r[i] != "$": t = table[r[i]] if r[i+1] in t[0]: total += t[0][r[i+1]] i += 2 else: total += t[1] i += 1 if total > 3999: print("ERROR") raise SystemExit def get(n, i, v, x): c = ["", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix"][n] return c.replace("i", i).replace("v", v).replace("x", x) s = "" t = total // 1000 total = total % 1000 s += get(t, "M", "!", "*") t = total // 100 total = total % 100 s += get(t, "C", "D", "M") t = total // 10 total = total % 10 s += get(t, "X", "L", "C") s += get(total, "I", "V", "X") print(s)