#include<bits/stdc++.h>
using namespace std;
int a[100005];
int q[100005];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];
	int length=1;
	q[length]=a[length];
	for(int i=2;i<=n;i++){
		if(q[length]<a[i]){
			q[++length]=a[i];
		}
		else{
				int l=1;
				int r=length;
				while(l<r){
					int mid=l+r>>1;
					if(q[mid]>=a[i]) r=mid;
					else l=mid+1;
				}
				q[l]=a[i];
		}
	}
	cout<<length<<endl;
}
