from collections import defaultdict N = int(input()) A = list(map(int,input().split())) cnt = defaultdict(int) for a in A: cnt[a] +=1 one = [] two = [] other = 0 for key in cnt.keys(): if cnt[key] == 1: one.append(key) elif cnt[key] == 2: two.append(key) else: other +=1 setA = set(A) for i in range(N+1): if i in setA: pass else: ans = i break one.sort() two.sort() if len(one) >= 1: co = -1 if len(one) >=2: co = one[1] if len(two) >= 1 and two[-1] > one[0]: co = max(co,two[-1]) if co == -1: ans = min(ans,one[0]) else: ans = min(ans,co) else: pass print(ans)