N = int(input()) A = tuple(map(int,input().split(" "))) t = N for i in range(N-1,-1,-1): if A[i] == t: t -= 1 print(t)