//f[i]:长为i的LIS末位的最小值
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int f[1000010];
int main(){
memset(f,0x3f,sizeof(f));
int n; cin>>n;
for(int i = 1; i <= n; i++){
int x; cin>>x;
*lower_bound(f+1,f+n+1,x) = x;
}
cout<<lower_bound(f+1,f+n+1,f[0])-f-1<<"\n";
return 0;
}