import Data.Maybe
data RomanFigure = I | V | X | L | C | D | M deriving (Show,Eq,Ord,Enum,Read)

main = interact $ unlines.map (show.rfToInt).lines

toInt :: RomanFigure -> Int
toInt x = fromMaybe 0 $ lookup x [(I,1),(V,5),(X,10),(L,50),(C,100),(D,500),(M,1000)]

rfToInt :: String -> Int
rfToInt = sum.map calcRF.divisioRF.strToRF
strToRF :: String -> [RomanFigure]
strToRF str = map (read.(:[])) str
divisioRF :: [RomanFigure] -> [[RomanFigure]]
divisioRF []         = []
divisioRF [c1]       = [[c1]]
divisioRF (c1:c2:cs) = case compare c1 c2 of
                          GT -> (c1:gstr1) : divisioRF rest1
                          EQ -> gstr2 : divisioRF rest2
                          LT -> [c1,c2]:divisioRF cs
                        where (gstr2,rest2) = span (== c1) (c1:c2:cs)
                              minNums       = takeWhile (== c2) (c2:cs)
                              (gstr1,rest1) = if length minNums <= 4 then span (== c2) (c2:cs)
                                                                     else splitAt 4 (c2:cs)

calcRF (c1:c2:cs) = case compare c1 c2 of
                      LT -> toInt c2 - toInt c1
                      otherwise -> sum.map toInt $ (c1:c2:cs)