char = {}
char["I"] = 1
char["V"] = 5
char["X"] = 10
char["L"] = 50
char["C"] = 100
char["D"] = 500
char["M"] = 500
while input = gets
  chars = input.chomp.split("")
  n = chars.size
  n.times{|i|
    chars[i] = char[chars[i]]
  }
  (n-1).downto(1){|i|
    if chars[i] > chars[i-1]
      chars[i] -= chars[i-1]
      chars[i-1] = 0
    end
  }
  p chars.inject(:+)
end