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
  i =0
  while i<line.size()-1
    a = hash[line[i]]
    b = hash[line[i+1]]
    if a<b
      ans += b-a
      i+=1
    else ans +=a
    end
    i+=1
  end
  if(i<line.size)
    ans+=hash[line[i]]
  end
  puts ans
end