while line = gets
  moji = Array.new
  num = Array.new
  line.each_char {|b| moji << b }
  moji.each do |moji1|
    puts moji1
    case( moji1.upcase )
    when "I" then
      num << 1
    when "V" then
      num << 5
    when "X" then
      num << 10
    when "L" then
      num << 50
    when "C" then
      num << 100
    when "D" then
      num << 500
    when "M" then
      num << 1000
    else
    end
  end
  puts num
  
  ret = 0
  
  i = num.length - 1
  puts i
  while i >= 0 do
    puts i
    if i == num.length - 1
      ret += num[i]
    elsif num[i] < num[i+1]
      ret -= num[i]
    else
      ret += num[i]
    end
    i = i - 1
  end
  puts ret
  break
end