N = int(input()) A = list(map(int,input().split())) D = {v:i for i,v in enumerate(A)} import sys for i in range(N,1,-1): if D[i] < D[i+1]: print(i-1) exit() print(0)