N=int(input()) list=list(map(int,input().split()))[::-1] x=N cnt=0 for i in range(N): if list[i]==x: x-=1 cnt+=1 print(N-cnt)