#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const int INF = 1 << 30;
int a[100000];
int dp[100000];
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;
}
