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