import sys input=lambda: sys.stdin.readline().rstrip() import bisect n=int(input()) A=[int(i) for i in input().split()] L=[] for a in A: if not L or a>L[-1]: L.append(a) else: L[bisect.bisect_left(L,a)]=a print(n-len(L))