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