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

current = 0
max = A.first
word = 1

before_a = A.shift

A.each do |a|
  if a > before_a
    if word == 1
      word += 1
      max = a
      current = 1
    elsif a > max
      current = (current.to_s(word) + '0'*(a-max)).to_i(base=word)
      max = a
    end
  else
    if word == 1
      word += 1
      current = 1
    else
 #     p a
  #    p (current.to_s(word)[0...a]).to_i(base=word)
      next_cnt = current.to_s(word).rjust(max, '0')[0...a].ljust(max, '0').to_i(base=word) + word**(max-a)
      if next_cnt >=  word**max
        word += 1
#        p "word++"
      end
      current = next_cnt
    end
  end
  before_a = a
#  p [current, max, word]
end

p word
