Roma = {"I" => 1, "V" => 5, "X" => 10, "L" => 50, "C" => 100, "D" => 500, "M" => 1000}
Minus = {"V" => 1, "X" => 1, "L" => 10, "C" => 10, "D" => 100, "M" => 100}
def toa(arg)
  temp = 1000
  return arg.inject(0){|sum, i|
    if Roma[i] > temp
      temp = Roma[i]
      sum - 2 * Minus[i] + Roma[i]
    else
      temp = Roma[i]
      sum + Roma[i]
    end
  }
end
while num = gets
  puts toa(num.chomp.split(//))
end