#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;
int n, a, dp[100010];

int main(void) {
    cin >> n;

    fill(dp, dp + n + 1, INF);
    dp[0] = -1;
    for (int i = 0; i < n; i++) {
        cin >> a;
        *(lower_bound(dp, dp + n + 1, a)) = a;
    }

    cout << lower_bound(dp, dp + n + 1, INF) - (dp + 1) << endl;

    return 0;
}
