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