N = gets.to_i - 1
H = gets.split.map(&:to_i)

c = 0

(0..N).each do |l|
    while H[l] != 0 do
        for r in (l..N)
            if H[r] >= 1
                H[r] -= 1
            else
                break
            end
        end
        c += 1
    end
end

puts c
