from collections import Counter n = int(input()) a = list(map(int, input().split())) c = Counter(a) sm = 0 for i in range(1<<20): sm += c[i] if c[i] < 2: if sm < n and c[i]: i += 1 print(i) break