#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MAX = 100100;

int main() {
    int n;
    cin >> n;
    vector<int> dp(MAX, INF);
    while (n--) {
        int e; cin >> e;
        *lower_bound(dp.begin(), dp.end(), e) = e;
    }
    cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
    return 0;
}
