N = gets.to_i
h = gets.split(' ').map(&:to_i)
cnt = 0
while h.max != 0
  l = 0
  while l < N && h[l] == 0 
    l += 1
  end
  r = l
  while r < N && h[r] > 0
    r += 1
  end
  l.upto(r - 1) do |i|
    h[i] -= 1
  end
  cnt += 1
end

puts cnt