N = int(input()) A = list(map(int, input().split())) Ai = [0] * N for i in range(N): Ai[A[i] - 1] = i ans = 0 for i in range(N - 1): if Ai[i] > Ai[i + 1]: ans = i + 1 print(ans)