
#include <bits/stdc++.h>

using namespace std;

const int INF = (int) 1e9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int a[n], dp[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 << '\n';

    return 0;
}

