def main(): N = int(input()) A = {j: i for i, j in enumerate(map(int, input().split()))} len_ = 0 for i in range(N, 1, -1): l = 0 while i > 1: if A[i] > A[i-1]: l += 1 else: break i -= 1 len_ = max(len_, l) print(N - 1 - len_) main()