def roman_to_arabic(roman)
  roman_arabic = {
    'I' => 1,
    'V' => 5,
    'X' => 10,
    'L' => 50,
    'C' => 100,
    'D' => 500,
    'M' => 1000
  }

  arabic = 0
  stack = roman.split('')
  while stack.any?
    a = stack.shift
    b = stack.shift
    left, right = roman_arabic[a], roman_arabic[b]
    if right.nil?
      arabic += left
    else
      arabic += (left < right) ? right - left : left + right
    end
  end
  arabic
end

while line = gets
  puts roman_to_arabic(line.chomp)
end