#include<iostream> using namespace std; const int maxn=100000; int a[maxn], b[maxn],n; int Search(int num, int low, int high) { int mid; while(low<=high) { mid=(low+ high)/2; if(num>=b[mid]) low=mid+1; else high=mid-1; } return low; } int main() { int len, pos; cin>>n; for(int i=1; i<=n; i++) cin>>a[i]; b[1]=a[1]; len=1; for(int i=2; i<=n; i++) { if(a[i]>=b[len]) { len++; b[len]=a[i]; } else { pos=Search(a[i],1,len); b[pos]=a[i]; } } cout<<len<<endl; return 0; }