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: if other: if len(one) >= 2: ans = min(ans,one[1]) else: if len(two) >= 1 and two[-1] > one[0]: if len(one) >= 2: co = max(two[-1],one[1]) else: co = two[-1] ans = min(co,ans) if len(one) >=2: ans = min(ans,one[1]) else: ans = min(ans,one[0]) else: pass print(ans)