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