N=int(input()) res=N V=list(map(int,input().split())) for i in reversed(range(N)): if res==V[i]: res-=1 print(res)