#include<cstdio>
#include<vector>
using namespace std;

long long b;
vector <long long> V;
int N;

void index(int index,long long a){
	int l = 0;
	if (V.back() < a)V.push_back(a);
	while (l + 1 < index){
		int m = (l + index) / 2;
		if (V[m] < a)l = m;
		else index = m;
	}
	V[l] = a;
	return;
}

int main(){
	scanf_s("%d", &N);
	for (int i = 0; i < N; i++){
		scanf_s("%lld", &b);
		if (!i)V.push_back(b);
		else index(i, b);
	}
	printf("%d\n", V.size());
}