#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
int a[N];
int b[N];
int Search(int num, int low, int high){
int mid;
while(low <= high){
mid = (low + high)/;
if(num >= b[mid]) low = mid + ;
else high = mid - ;
}
return low;
}
int DP(int n){
int i, len, pos;
b[] = a[];
len = ;
for(i = ; i <= n; i++){
if(a[i] >= b[len])
b[++len] = a[i];
else{
pos = Search(a[i],,len);
//在b[]数组中找出第一个比a[i]大的位置并且让a[i]替代这个位置
b[pos] = a[i];
}
}
return len;
}
int main(){
int n, i, j;
scanf("%d", &n);
for(i = ; i <= n; ++i)
scanf("%d", &a[i]);
int len = DP(n);
printf("%d\n", len);
return ;
}