import System.IO (isEOF)

main = do
    quit <- isEOF
    if quit then return () else do
        getLine >>= return . solve >>= print
        main

solve :: String -> Int
solve cs = accum 0 $ map c2n cs
    where
    c2n 'I' = 1
    c2n 'V' = 5
    c2n 'X' = 10
    c2n 'L' = 50
    c2n 'C' = 100
    c2n 'D' = 500
    c2n 'M' = 1000

    accum acc []        = acc
    accum acc (n0:n1:ns)
        | n0 < n1       = accum (acc+n1-n0) ns
    accum acc (n:ns)    = accum (acc+n) ns