require 'json'

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

nsin = 2
keta = A[0]
value = 0

(1..A.length-1).each do |i|
  ai = A[i]
  before = A[i-1]

  if ai > before # aaa -> aaaa
    next
  elsif ai == before # aaa -> aab
    value += 1
    if nsin ** keta <= value
      nsin += 1
    end
  else # aaa -> ab
    value += 1
    if value < (nsin ** (keta-ai))
      value = (nsin ** (keta-ai))
    end
    if nsin ** keta <= value
      nsin += 1
    end
  end
end

puts nsin
