N = int(input()) A = [int(i) for i in input().split()] M = N c = 0 for i in reversed(range(N)): if M == A[i]: c += 1 M -= 1 print(N - c)