#include<iostream>
using namespace std;

const int INF = 1<<30;

int main(){
    int n, a;
    cin >> n;

    int l[n];
    for(int i = 0; i < n; i++)  l[i] = INF;

    for(int i = 0; i < n; i++){
        cin >> a;
        *(lower_bound(l, l+n, a)) = a;
    }

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

    return 0;
}
