let rn_to_an r = 
  if r = "M" then 1000
  else if r = "D" then 500
  else if r = "C" then 100
  else if r = "L" then 50
  else if r = "X" then 10
  else if r = "V" then 5
  else if r = "I" then 1
  else 0

let rec sum_rm = function
  | [] -> 0
  | [x] -> x
  | x :: y :: rest when x < y -> y - x + sum_rm rest
  | x :: y :: rest -> x + sum_rm (y :: rest)

let _ =
  try
    while true do
      let rlst = List.map rn_to_an (Str.split (Str.regexp "") (read_line ())) in
      Printf.printf "%d\n" (sum_rm rlst)
    done
  with
    End_of_file -> ()