#include <iostream>
#include <cstdio>
using namespace std;
int n, a, dp[100000];
int main() {
	scanf("%d",&n);
	fill(dp, dp+n, 1001001001);
	for (int i = 0; i < n; i++) {
		scanf("%d",&a);
		*lower_bound(dp, dp+n, a) = a;
	}
	printf("%d\n", (int)(lower_bound(dp, dp+n, 1001001001)-dp));
}