#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1001001001;
int a[100100];
int dp[100100];

int main() {
    int n;
    cin >> 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 << endl;
    return 0;
}
