from bisect import * N = int(input()) a = list(map(int, input().split())) dp = [10**18] * (N + 1) dp[0] = 0 for ai in a: i = bisect_right(dp, ai) dp[i] = ai for i in range(N, -1, -1): if dp[i] != 10 ** 18: res = i break print(N - res)