#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define NMAX 100000

int a[NMAX+1];
int len;
int Lent[NMAX+1];

int main() {
	int n,i,j;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	
	Lent[0]=a[0];
	len=1;
	
	for(i=1;i<n;i++) {
		if(Lent[len-1]<a[i]) {
			Lent[len++]=a[i];
		} else {
			*lower_bound(Lent,Lent+len,a[i])=a[i];
		}
	}
	
	printf("%d\n",len);
	
	return 0;
}
