#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    int n, a;
    cin >> n;
    vector<int> b(n, 2e9);
    rep(i, n) {
        cin >> a;
        int j = lower_bound(b.begin(), b.end(), a) - b.begin();
        b[j] = a;
    }
    int ans = 0;
    rep(i, n) {
        if (b[i] < 2e9) ans = i + 1;
    }
    cout << ans << "\n";
}
