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