#include <bits/stdc++.h>
using namespace std;

#define INF (1<<30)
#define MAX_N 100000

int n;
int a[MAX_N];

int dp[MAX_N];

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

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

	cout << ans << endl;

	return 0;
}

