def function(ary)
    tmp = []
    sum = []
    ary.length.times do |i|
        if ary[i] != 0 then
            tmp << ary[i]
        else
            if tmp.length > 0 then
                sum << tmp
            end
            tmp = []
        end
        if i == ary.length - 1 && tmp.length != 0 then
            sum << tmp
        end
    end
    sum
end

N = gets.chomp.to_i
h = gets.split(' ')
h = h.map{|x| x.to_i}

f = 1
count = 0
while f == 1 do
    t = function(h)
    if t.length == 0 then
        f = 0
        break
    end
    count += t.length
    h = h.map do |x|
        if x > 0 then
            x - 1
        else
            0
        end
    end
end

print count