#include<cstdio>
#include<algorithm>
#include<iterator>

int s[100000];
int dp[100000];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &s[i]);

	std::fill_n(dp, n, 1e9);
	for (int i = 0; i < n; i++) {
			*std::lower_bound(dp, dp + n, s[i])=s[i];
	}
	
	printf("%d\n", std::distance(dp, std::lower_bound(dp,dp+n,1e9)));
}
