#include <iostream>
using namespace std;
const int MAX = 100005;
const int INF = 1000000005;
int a[MAX];
int dp[MAX];


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

	for (int i = 0; i < MAX; ++i)
	{
		dp[i] = INF;
	}

	for (int i = 0; i < n; ++i)
	{
		*lower_bound(dp, dp+n, a[i]) = a[i];
	}

	cout << lower_bound(dp, dp+n, INF) - dp << endl;
	return 0;
}
