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