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

ans = 0

until h.all?{|v| v.zero? }
  l = h.find_index{|v| v > 0}
  r = l
  r += 1 while r < h.length && h[r] > 0
  (l...r).each {|i| h[i] -= 1}
  ans += 1
end
puts ans
