#include <iostream>
#define nmax 100000
using namespace std;

int l[nmax],a[nmax+1];
int n;

int lis(){
    l[0] =a[0];
    int len=1;
    for (int i = 1; i <n; ++i) {
        if (l[len-1]<a[i]){
            l[len++]=a[i];
        } else{
            *lower_bound(l,l+len,a[i])=a[i];
        }
    }
    return len;
}

int main() {
    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin>>a[i]
    }
    cout<<lis()<<endl;
    return 0;
}