import collections N = int(input()) A = list(map(int, input().split())) CA = collections.Counter(A) ans = 0 amari = False for k,v in CA.items(): if v>=3: amari=True while CA[ans]>=2: ans+=1 if CA[ans] and ans*2+1=2: ans+=1 print(ans)