from bisect import bisect_left n = int(input()) A = list(map(int, input().split())) B = [] for a in A: p = bisect_left(B, a) if p == len(B): B.append(a) else: B[p] = a print(n - len(B))