local N = io.read("n")
local h = {}
for i=1,N do
    h[i] = io.read("n")
end

local cnt = 0
for i=1,100 do
    local btb = false
    for j=1,N do
        if h[j] == 0 then
            if btb then
                btb = false
            end
        else
            if not btb then
                btb = true
                cnt = cnt + 1
            end
            h[j] = h[j] - 1
        end
    end
end

print(cnt)