n = gets.to_i
a = []
a += gets.split.map(&:to_i) until a.size == n
h = {}
(0..n-1).each do |i|
  x = 0
  (i..n-1).each do |j|
    x = x * 10 + a[j]
    h[x] = 1
  end
end
0.upto(Float::INFINITY) do |i|
  if !h[i]
    p i
    break
  end
end
