#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n, inf = 1000000000;
	scanf("%d", &n);
	vector<int> a(n, inf);
	for(int i = 0, j; i < n; ++i)
	{
		scanf("%d", &j);
		*lower_bound(a.begin(), a.end(), j) = j;
	}
	printf("%ld\n", distance(a.begin(), lower_bound(a.begin(), a.end(), inf)));
}

