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