#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> arr;
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(arr.empty()){
arr.push_back(x);
}
else if(x>arr.back()){
arr.push_back(x);
}
else{
*lower_bound(arr.begin(),arr.end(),x)=x;
}
}
cout<<arr.size();
return 0;
}
02-23
179
01-21
227
10-02
183
01-19
417
10-02
573