N = gets.to_i
hs = gets.split.map(&:to_i)

ans = 0
while hs.size > 0
    while hs[0] > 0
        ans += 1
        hs.size.times do |i|
            if hs[i] > 0
                hs[i] -= 1
            else
                break
            end
        end
    end
    hs.shift
end
puts ans