#include<cstdio>
#include<iostream>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
const int N = 5005;
int num[N], f[N];
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> num[i];
}
int len = 0;
f[++ len] = num[1];
for(int i = 2; i <= n; i ++){
int pos = lower_bound(f + 1, f + len + 1, num[i]) - f;
if(pos == len + 1){
f[++ len] = num[i];
}else{
f[pos] = num[i];
}
}
cout << len << endl;
return 0;
}