input = STDIN.read.split("\n").map{|l| l.split(" ").map{|a| a.to_i}}

N = input[0][0]
h = input[1]
yari = 0

while true
    has_yari = false
    yaring = false
    for i in 0..(h.length - 1)
        if h[i] > 0 && yaring == false
            yari = yari + 1
            yaring = true
            has_yari = true
        end

        if h[i] <= 0 && yaring == true
            yaring = false
            has_yari = true
        end
    end

    if has_yari == false
        break
    end
    h = h.map{|i| i - 1}
end

puts yari