RF = { 'I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000 }

while l = gets
  rfs = l.chomp.split(//)
  puts rfs.each_cons(2).map { |i, j|
    (RF[i] >= RF[j] ? 1 : -1) * RF[i]
  }.inject(:+) + RF[rfs[-1]]
end