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

while gets
	roman = $_.chomp.upcase
	nums = pn = []
	1.upto(roman.size-1) do |i|
		pn << (rh[roman[i]] > rh[roman[i-1]] ? -1 : 1)
	end
	pn << 1
	0.upto(roman.size-1) {|i| nums[i] = rh[roman[i]] * pn[i]}
	puts nums.inject {|x,y| x+y}
end