function main()
    parse_int(x) = parse(Int, x)
    readline()
    line = parse_int.(split(readline()))
    steps = 0
    current_max = 0
    for n in line
        if n > current_max
            current_max = n
        end
        steps += current_max - n
        return steps
    end
end

println(main())
