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