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

while start<=n-1
  if h[start]==0
    start += 1 
    next
  end
  (start..n-1).each do |i|
    h[i]==0 ? break : h[i] -= 1
  end
  result += 1
end

puts result