#include <iostream>
#include <algorithm>
using namespace std;

const int INF = 1<<30; // 2 ^ 30
const int MAXN = 100*1000;

int a[MAXN+10];
int d[MAXN+10];
int last[MAXN+10];

int main(){
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for(int i=0; i<n; i++)
		cin >> a[i];

	for(int i=0; i<n; i++)
		last[i] = INF;
	last[0] = 0;

	int best = 0;

	for(int i=0; i<n; i++){
		int j = lower_bound(last, last+n, a[i]) - last - 1;
		d[i] = j+1;
		last[j+1] = min( last[j+1] , a[i] );

		best = max( best , d[i] );
	}
	
	cout << best << endl;

	return 0;
}