import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,*A = map(int,read().split()) def longest_increasing_subsequence(seq, wider_sense = True): from bisect import bisect_left, bisect_right f = bisect_right if wider_sense else bisect_left N = len(seq) INF = 10**18 dp = [INF] * (N+1) for x in seq: i = f(dp,x) dp[i] = x return f(dp,INF-1) answer = N - longest_increasing_subsequence(A, False) print(answer)