n=int(input()) a=[int(i)for i in input().split()] for i in a[::-1]: if i==n: n-=1 print(n)