import bisect n = int(input()) a = list(map(int, input().split())) dp = [] for x in a: pos = bisect.bisect_left(dp, x) if pos == len(dp): dp.append(x) else: dp[pos] = x print(n - len(dp))