#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
const int num = 100001, INF = 2000000000;
int a[num];
int dp[num];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	fill(dp, dp + n, 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;
}