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

c = 0

while h.inject(:+) > 0
  l = h.index(h.max)
  r = l

  while h[r+1] == h.max
    r += 1
  end

  h.map!.with_index{|k, i| (l..r).include?(i) ? k-1 : k}
  
  c += 1
end

puts c
