N = int(input()) A = input().split()[::-1] for a in A: N -= int(a) == N print(N)