import collections N = int(input()) A = list(map(int, input().split())) CA = collections.Counter(A) ans = 0 while CA[ans]>=2: ans+=1 if CA[ans] and ans*2+1=2: ans+=1 print(ans)