import bisect n = int(input()) a = list(map(int, input().split())) tails = [] for x in a: j = bisect.bisect_right(tails, x) if j == len(tails): if not tails or x > tails[-1]: tails.append(x) else: tails[j] = x print(n - len(tails))