#!/usr/bin/env ruby

class Object
  def tapp
    debug = false
    if debug
      require 'PP'
      tap { PP.pp(self, $stderr) }
    else
      self
    end
  end
end

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

s = nil
max = nil
as.each do |a|
  a = [a, 1000].min.tapp
  if !s
    s = [0] * a
    max = 0
  else
    if a > s.size
      s += [0] * (a - s.size)
    else
      if s[0...a].all? { |i| i == max }
        max += 1
        s = [0] * (a - 1) + [max]
      else
        s = s[0...a]
        s.size.times do |i|
          if s[a - 1 - i] == max
            s[a - 1 - i] = 0
          else
            s[a - 1 - i] += 1
            break
          end
        end
      end
    end
  end
  s.tapp
end

puts(max + 1)