n = gets.to_i
h = gets.split.map(&:to_i)

ans = 0
loop do
    c = 0
    pre = -1
    n.times do |i|
        if h[i] == 0
            pre = i
        elsif pre == i - 1
            h[i] -= 1
            c += 1
        else
            h[i] -= 1
        end
    end

    c == 0 ? break : ans += c
end

puts ans