Roman = { 'I'=>1, 'V'=>5, 'X'=>10, 'L'=>50, 'C'=>100, 'D'=>500, 'M'=>1000 }
while gets
    array = $_.chomp.scan(/./).map{|x| Roman[x]}
    (0..array.length-2).each do |i|
        if array[i+1] > array[i]
            array[i] = -array[i]
        end
    end

    puts array.inject(0){|sum, x| sum + x}
end