n=int(input()) a=list(map(int,input().split())) ans=0 target=n for i in range(n-1,-1,-1): if a[i]==target: target-=1 else: ans+=1 print(ans)