table={"I"=>1,"V"=>5,"X"=>10,"L"=>50,"C"=>100,"D"=>500,"M"=>1000}
while s=STDIN.gets
    sum=0
    s=s.chomp
    for i in 0..s.length-1 do
        if i < s.length-1 and table[s[i]] < table[s[i+1]] then
            sum = sum - table[s[i]] 
        else
            sum = sum + table[s[i]]
        end
    end
    print sum,"\n"
end