output_description: Print the minimum possible number of different characters contained in the
  strings.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_N
attempt: # -*- coding: utf-8 -*-
  
  from sys import stdin
  
  
  def load():
      n = stdin.readline()
      data = [int(x) for x in stdin.readline().split()]
      return data
  
  
  def calc(data):
      total = 1
      old = [1] * data.pop(0)
  
      for x in data:
          done = False
          countUp = False
          curr = [1] * x
          length = min(len(curr), len(old))
          for i in range(length - 1, -1, -1):
              if not done:
                  if old[i] >= total:
                      ok, upIndex = ketaage(old, i, total)
                      if not ok:
                          if len(curr) > length:
                              curr[-1] = 1
                          else:
                              countUp = True
                      else:
                          old[upIndex] += 1
                          for j in range(length - 1, upIndex, -1):
                              curr[j] = 1
                              old[j] = 1
                  else:
                      old[i] += 1
                      for j in range(length - 1, i, -1):
                          curr[j] = 1
                          old[j] = 1
                  done = True
              curr[i] = old[i]
          if countUp:
              total += 1
              curr[-1] = total
  
          old = curr
      return total
  
  
  def ketaage(curr, i, total):
      if curr[i] < total:
          return True, i
      elif i == 0:
          return False, -1
      else:
          return ketaage(curr, i - 1, total)
  
  
  data = load()
  print(calc(data))
  
problem_description: Statement
  
  There are N strings arranged in a row. It is known that, for any two adjacent
  strings, the string to the left is lexicographically smaller than the string
  to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is
  the i-th string from the left.
  
  At least how many different characters are contained in S_1,S_2,...,S_N, if
  the length of S_i is known to be A_i?
samples: [{"input": "3\n    3 2 1", "output": "2\n    \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n    2 3 2 1 2", "output": "2"}]