" Reference: https://qiita.com/tatyam/items/492c70ac4c955c055602" # ※ 計算量が O(sqrt(N)) per query なので, 過度な期待はしないこと. from bisect import bisect_left, bisect_right class Sorted_Set: BUCKET_RATIO=50 REBUILD_RATIO=170 def __init__(self, A=[]): A=list(A) if not all(A[i]len(self.list)*self.REBUILD_RATIO: self.__build() return True def discard(self, x): if self.N==0: return False A=self.__find_bucket(x) i=bisect_left(A, x) if not(i!=len(A) and A[i]==x): return False # x が存在しないので... A.pop(i) self.N-=1 if len(A)==0: self.__build() return True def remove(self, x): if not self.discard(x): raise KeyError(x) #=== get, pop def __getitem__(self, index): if index<0: index+=self.N if index<0: raise IndexError("index out of range") for A in self.list: if index=value: return A[bisect_left(A,value)] else: for A in self.list: if A[-1]>value: return A[bisect_right(A,value)] #=== count def less_count(self, value, equal=False): """ a < value となる S の元 a の個数を求める. equal=True ならば, a < value が a <= value になる. """ count=0 if equal: for A in self.list: if A[-1]>value: return count+bisect_right(A, value) count+=len(A) else: for A in self.list: if A[-1]>=value: return count+bisect_left(A, value) count+=len(A) return count def more_count(self, value, equal=False): """ a > value となる S の元 a の個数を求める. equal=True ならば, a > value が a >= value になる. """ return self.N-self.less_count(value, not equal) #=== def is_upper_bound(self, x, equal=True): if self.N: a=self.list[-1][-1] return (avalue: i=bisect_left(A, value) if A[i]==value: return index+i else: raise ValueError("{} is not in Set".format(value)) index+=len(A) raise ValueError("{} is not in Set".format(value)) #================================================== 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 mex=0 while C[mex]: mex+=1 return mex #================================================== print(solve())