while line = gets
  line.chomp!
  ans =0
  ans += line.scan(/XL/).size*40
  line.gsub!(/XL/,"")
  ans += line.scan(/XC/).size*90
  line.gsub!(/XC/,"")
  ans += line.scan(/IX/).size*9
  line.gsub!(/IX/,"")
  ans += line.scan(/IV/).size*4
  line.gsub!(/IV/,"")
  ans += line.scan(/CD/).size*400
  line.gsub!(/CD/,"")
  ans += line.scan(/DM/).size*500
  line.gsub!(/DM/,"")
  line = line.split("")
  line.each do |c|
    case c
    when 'X'
      ans +=10
    when 'I'
      ans +=1
    when 'L'
      ans +=50
    when 'D'
      ans +=500
    when 'C'
      ans+=100
    when 'M'
      ans+=1000
    when 'V'
      ans+=5
    end
  end
  puts ans
end