table = {
  "I" => 1,
  "IV" => 4,
  "V" => 5,
  "IX" => 9,
  "X" => 10,
  "XL" => 40,
  "L" => 50,
  "XC" => 90,
  "C" => 100,
  "CD" => 400,
  "D" => 500,
  "M" => 1000
}

while input = gets
  input.chomp!
  sum = 0

  loop do
    unless input.sub!(/(IV|IX|XL|XC|CD)/) { |roman| sum += table[roman]; nil }
      break
    end
  end

  input.each_char do |roman|
    sum += table[roman]
  end

  puts sum
end