from collections import Counter n = int(input()) A = list(map(int,input().split())) A.sort() if A[0] != 0: print(0) exit() C = Counter(A) s = sorted(C.keys()) more = 0 done = 0 last = -1 for x in s: if last+1 != x: print(last+1) exit() last = x if C[x] == 2: continue if C[x] > 2: more = 1 continue if x != max(s) or more: if done: print(x) exit() else: done = 1 else: print(x) exit() print(last+1)