import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

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

calc s = calc' 0 s
  where
    calc' r [] = r
    calc' r (a:[]) = r + a
    calc' r (a:bs@(b:cs))
      | a < b = calc' (r+b-a) cs
      | otherwise = calc' (r+a) bs

main = do
    map (calc . map cvt) . lines <$> getContents >>= mapM_ print 