hash = {'I'=>1,'V'=>5,'X'=>10,'C'=>100,'D'=>500,'L'=>50,'M'=>1000}
while line = gets
  line.chomp!
  line = line.split("")
  ans =0
  line.each_slice(2) do |a|
    if(hash[a[0]]<hash[a[1]])
      ans +=hash[a[1]]-hash[a[0]]
    else ans +=hash[a[1]]+hash[a[0]]
    end
  end
  puts ans
end