import           Control.Applicative
import           Data.Char
import           Data.List

main :: IO ()
main = getContents >>= print . toArabic . lines

toArabic :: String -> Int
toArabic = snd . foldl f (0, 0)
  where f (prev, sum) c
          | prev < toArabic' c = (toArabic' c, sum + toArabic' c - 2 * prev)
          | otherwise          = (toArabic' c, sum + toArabic' c)

        toArabic' 'M' = 1000
        toArabic' 'D' = 500
        toArabic' 'C' = 100
        toArabic' 'L' = 50
        toArabic' 'X' = 10
        toArabic' 'V' = 5
        toArabic' 'I' = 1
        toArabic' _   = 0