#方針: 横にスライスして、島の数を数える

n = gets.to_i
h = gets.split.map(&:to_i)
now = [0]*n
ans = 0

while !h.all?{|h| (h<=0)}
  cnt=0
  l = 0
  dl = 0
  while l < h.length
    if h[l]<=0
      l+=1
      next
    end

    while l+dl < h.length && h[l+dl]>0
      dl+=1
    end
    cnt+=1
    l = l+dl
    dl = 0
  end
  ans += cnt
  h = h.map{|h| h-1}
end

p ans