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

int n, a[100050], l[100050], len = 1;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	l[1] = a[1];

	for (int i = 2; i <= n; i++)
	{
		if (a[i] > l[len])
			l[++len] = a[i];
		else
			*lower_bound(l + 1, l + len + 1, a[i]) = a[i];
	}

	cout << len << endl;
	return 0;
}
