#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
const int MAXN=10240;
int f[MAXN];
int doing(){
freopen("lis1.out","w",stdout);
freopen("lis1.in","r",stdin);
int N;scanf("%d",&N);
memset(f,63,sizeof(f));
for(int x,i=1;i<=N;++i){
scanf("%d",&x);
*std::lower_bound(f+1,f+N+1,x)=x;
}printf("%d\n",std::lower_bound(f+1,f+N+1,*f)-f-1);
}
int k=doing();
int main(){;}