n=int(input()) a=list(map(int,input().split())) inf=float('inf') dp=[inf]*(n+1) dp[0]=0 # dp[i]:長さiの単調増加列の最小末尾 from bisect import bisect_left as bl for x in a: idx=bl(dp,x) dp[idx]=min(dp[idx],x) idx=bl(dp,n+1)-1 print(n-idx)