#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, a;
	cin >> n;
	vector<int> b;
	for (int i = 0; i < n; i++) {
		cin >> a;
		vector<int>::iterator c = lower_bound(b.begin(), b.end(), a);
		if (c == b.end()) b.push_back(a);
		else *c = a;
	}
	cout << b.size() << endl;
}
