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