m=10**5+10 n=int(input()) a=list(map(int,input().split())) mx=max(a) a.remove(mx) cnt=[0]*m for i in a: cnt[i]+=1 use=0 flag=0 for i in range(m): if cnt[i]==0: print(i) exit() if cnt[i]==1: if flag: print(i) exit() else: flag=1