import strutils, sequtils, algorithm let N = stdin.readline.parseInt A = stdin.readline.split.map(parseInt) var lis = newSeq[int]() for a in A: let lb = lis.lowerBound(a) if lb == lis.len: lis.add(a) else: lis[lb] = min(lis[lb], a) echo(N - lis.len)