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