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