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