#include<iostream>
#include <algorithm>
using namespace std;
#define INF 1000000000

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

