_n = gets.to_i
as = gets.split.map(&:to_i)

n = as.first
len = n
curr = [[0,0],[n,1]]
max = 1

as[1..-1].each do |n|
  if len < n
    a,b = curr.pop
    if b == 1
      curr << [a+n-len,1]
    else
      curr << [a,b] << [n-len,1]
    end
  else # len >= n
    xi = -1
    xpos = -1

    i = 1
    pos = 0
    while i < curr.length
      a,b = curr[i]
      pos += a

      if b < max
        xi = i
        xpos = pos
      end

      break if n <= pos
      i += 1
    end

    if xi < 0
      xi = curr.length - 1
      xpos = pos
    end

    a,b = curr[xi]
    curr = curr[0..xi-1]
    x = [a-1,n-xpos+a-1].min
    curr << [x,b] if x != 0
    curr << [1,b+1]
    curr << [n-xpos,1] if n-xpos > 0
    max = b+1 if max < b+1
  end

  len = n
end

p max