fignum = {"I"=>1, "V"=>5, "X"=>10, "L"=>50, "C"=>100, "D"=>500, "M"=>1000}
while gets
  sum = 0
  r = $_.chomp.split("")
  fb = r.shift
  r.each do |f|
    if fb[-1] != f
      sum+=fignum[fb[0]]*fb.size if fignum[fb[0]]>fignum[f]
      sum-=fignum[fb[0]]*fb.size if fignum[fb[0]]<fignum[f]
      fb = f
    else
      fb << f
    end
  end
  sum+=fignum[fb[0]]*fb.size
  p sum
end