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