#================================================== def solve(): from collections import Counter N=int(input()) A=list(map(int,input().split())) A_max=max(A) C=[0]*(max(A)+2) for a in A: C[a]+=1 C[A_max]-=1 target=0 while C[target]<=1: C[target]+=1 break mex=0 while C[mex]>=2: mex+=1 return mex #================================================== print(solve())