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
  if(line.size%2==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
  else
    line[0...-1].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
    ans += hash[line[-1]]
  end
  puts ans
end