#include "bits/stdc++.h"
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    vector<int> dp(n + 1, INT32_MAX);
    for (int i = 0; i < n; ++i) {
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }

    cout << distance(dp.begin(), lower_bound(dp.begin(), dp.end(), INT32_MAX)) << endl;
}
