#include <iostream>
#include <algorithm>
using namespace std;
const int MAX=100000;
int main()
{
    int n,A[MAX],L[MAX+1],length=1;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>A[i];
    L[0]=-1;
    for(int i=0;i<n;i++)
    {
        if(A[i]>L[length-1])
        {
            L[length++]=A[i];
        }
        else{
            *lower_bound(L,L+length,A[i])=A[i];
        }
    }
    cout<<length-1<<endl;
    return 0;
}
