c = {'I'=> 1, 'V'=> 5, 'X'=>10, 'L'=>50, 'C'=>100, 'D'=>500, 'M'=>1000}
c.default = 0
readlines.each do |l|
  puts l.chars.each_cons(2).inject(0){|sum,(i,j)|
    c[i] < c[j] ? sum-c[i] : sum+c[i]
  }
end