import Data.Char

main = do
 getLine
 rs <- words <$> getLine
 putStrLn $ maybe "ERROR" id $ roman $ sum $ map arabic rs

roman n
 | n > 3999 = Nothing
 | otherwise = Just $ concat $ zipWith readArabic [1000,100,10,1] (digits n)
 where
  digits = reverse . take 4 . reverse . ([0,0,0] ++) . map digitToInt . show
  readArabic 1000 d
   | d == 0 = ""
   | otherwise = replicate d 'M'
  readArabic 100 d
   | d == 0 = ""
   | d <= 3 = replicate d 'C'
   | d == 4 = "CD"
   | d == 5 = "D"
   | d <= 8 = 'D' : replicate (d-5) 'C'
   | d == 9 = "CM"
  readArabic 10 d
   | d == 0 = ""
   | d <= 3 = replicate d 'X'
   | d == 4 = "XL"
   | d == 5 = "L"
   | d <= 8 = 'L' : replicate (d-5) 'X'
   | d == 9 = "XC"
  readArabic 1 d
   | d == 0 = ""
   | d <= 3 = replicate d 'I'
   | d == 4 = "IV"
   | d == 5 = "V"
   | d <= 8 = 'V' : replicate (d-5) 'I'
   | d == 9 = "IX"

arabic = sum . count . map readRoman
 where
  readRoman r = case r of {'I'->1; 'V'->5; 'X'->10; 'L'->50; 'C'->100; 'D'->500; 'M'->1000}
  count (x:y:xys) = if x<y then y-x : count xys else x : count (y:xys)
  count xs = xs