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