n,m=int(input()),1 for i in input().split(): if int(i)==m:m+=1 print(m-1)