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

n = as.first
len = n
curr = [[0,1],[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
    pos = len
    f = true
    k = -1
    (curr.length-1).downto(1) do |i|
      pos -= curr[i][0]
      if pos <= n
        if k < 0
          k = i
        end
        if curr[i][1] < max
          a,b = curr[i]
          curr = curr[0..i-1]
          x = n
          curr.each do |a,b|
            x -= a
          end
          if a > 1
            curr << [a-1,b]
            x -= a - 1
          end
          curr << [1,b+1]
          curr << [x-1,1] if x > 1
          f = false
          break
        end
      end
    end
    if f
      a,b = curr[k]
      curr = curr[0..k-1]
      x = n
      curr.each do |a,b|
        x -= a
      end
      if a > 1
        curr << [a-1,b]
        x -= a - 1
      end
      curr << [1,b+1]
      curr << [x-1,1] if x > 1
      max = b+1 if max < b+1
    end
  end

  len = n
end

p max
