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