n = int(input()) rom_nums = input().split() rom_dic = {"I":1, "V": 5, "X":10, "L":50, "C":100, "D":500, "M":1000} ara_num = 0 rom_sum = "" def get_key(a_num): return [k for k, v in rom_dic.items() if v == a_num][0] for i in rom_nums: for j in range(len(i) - 1): if rom_dic[i[j]] >= rom_dic[i[j + 1]]: ara_num += rom_dic[i[j]] else: ara_num -= rom_dic[i[j]] ara_num += rom_dic[i[-1]] ara_sum = str(ara_num) if int(ara_sum) > 3999: print("ERROR") else: for i in range(len(ara_sum)): digit = 10 ** (len(ara_sum) - 1 - i) if int(ara_sum[i]) == 4: rom_sum += (get_key(digit) + get_key(5 * digit)) elif int(ara_sum[i]) == 9: rom_sum += (get_key(digit) + get_key(10 * digit)) elif 0 <= int(ara_sum[i]) <= 3: rom_sum += (get_key(digit) * int(ara_sum[i])) else: rom_sum += (get_key(5 * digit) + get_key(digit) * (int(ara_sum[i]) - 5)) print(rom_sum)