import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,*A = map(int,read().split()) position = [0] * (N+1) for i,x in enumerate(A): position[x] = i x = 1 for n in range(N-1,0,-1): if position[n] < position[n+1]: x += 1 else: break answer = N - x print(answer)