def change(c)
  return 1 if c == 'I'
  return 5 if c == 'V'
  return 10 if c == 'X'
  return 50 if c == 'L'
  return 100 if c == 'C'
  return 500 if c == 'D'
  return 1000 if c == 'M'
  return 0
end

while gets do
  a = 0
  s = $_.split("")
  (s.size).times do |i|
    if change(s[i]) >= change(s[i+1]) then
      a += change(s[i])
    else
      a -= change(s[i])
    end
  end
  puts a
end