import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { public static final String[] strs = {"CM", "M", "CD", "D", "XC", "C", "XL", "L", "IX", "X", "IV", "V", "I"}; public static final int[] values = {900, 1000, 400, 500, 90, 100, 40, 50, 9, 10, 4, 5, 1}; public static int decode(String input){ if(input.startsWith("CM")){ return 900 + decode(input.substring(2)); }else if(input.startsWith("M")){ return 1000 + decode(input.substring(1)); }else if(input.startsWith("CD")){ return 400 + decode(input.substring(2)); }else if(input.startsWith("D")){ return 500 + decode(input.substring(1)); }else if(input.startsWith("XC")){ return 90 + decode(input.substring(2)); }else if(input.startsWith("C")){ return 100 + decode(input.substring(1)); }else if(input.startsWith("XL")){ return 40 + decode(input.substring(2)); }else if(input.startsWith("L")){ return 50 + decode(input.substring(1)); }else if(input.startsWith("IX")){ return 9 + decode(input.substring(2)); }else if(input.startsWith("X")){ return 10 + decode(input.substring(1)); }else if(input.startsWith("IV")){ return 4 + decode(input.substring(2)); }else if(input.startsWith("V")){ return 5 + decode(input.substring(1)); }else if(input.startsWith("I")){ return 1 + decode(input.substring(1)); }else{ return 0; } } public static String encode(int n){ if(n >= 1000){ return "M" + encode(n - 1000); }else if(n >= 900){ return "CM" + encode(n - 900); }else if(n >= 500){ return "D" + encode(n - 500); }else if(n >= 400){ return "CD" + encode(n - 400); }else if(n >= 100){ return "C" + encode(n - 100); }else if(n >= 90){ return "XC" + encode(n - 90); }else if(n >= 50){ return "L" + encode(n - 50); }else if(n >= 40){ return "XL" + encode(n - 40); }else if(n >= 10){ return "X" + encode(n - 10); }else if(n >= 9){ return "IX" + encode(n - 9); }else if(n >= 5){ return "V" + encode(n - 5); }else if(n >= 4){ return "IV" + encode(n - 4); }else if(n >= 1){ return "I" + encode(n - 1); }else{ return ""; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); int sum = 0; for(int i = 0; i < N; i++){ final int num = decode(sc.next()); sum += num; } if(sum > 3999){ System.out.println("ERROR"); }else{ System.out.println(encode(sum)); } } }