def mex(S): x=0 while x in S: x+=1 return x def solve(): from collections import Counter N=int(input()) A=list(map(int,input().split())) CA=Counter(A) S=set() for a in CA: if CA[a]>=2: S.add(a) return mex(S) #================================================== print(solve())