h = {
  'I' => 1,
  'V' => 5,
  'X' => 10,
  'L' => 50,
  'C' => 100,
  'D' => 500,
  'M' => 1000,
}
while roman = STDIN.gets
  roman.chomp!
  arabic=0
  prev=0
  roman.chars.reverse.each do |c|
    if h[c] < prev then
      arabic -= h[c]
    else
      arabic += h[c]
    end
    prev = h[c]
  end
  puts arabic
end