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

count = 0

while true
  # find l
  l = h.index {|item| item > 0}
  break if l.nil?

  # find r
  r = h[l..-1].index {|item| item <= 0}

  if r != nil
    r += l - 1
  else
    r = n - 1
  end

  l.upto(r) do |i|
    h[i] -= 1
  end

  count += 1
end

p count
