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