""" https://yukicoder.me/problems/no/365 """ import bisect def LIS(lis): seq = [] for c in lis: ind = bisect.bisect_left(seq,c) if ind == len(seq): seq.append(c) else: seq[ind] = c return len(seq) N = int(input()) A = list(map(int,input().split())) print (N - LIS([-A[i] for i in range(N-1,-1,-1)]) )