#include <stdio.h>
int divide_ffb(int a[],int l,int key);

int main()
{
    int n,i,a,b[1000],l,pos;
    while(~scanf("%d",&n))
    {
        scanf("%d",&a);
        b[0]=a;l=1;
        for(i=1;i<n;i++)
        {
            scanf("%d",&a);
            pos=divide_ffb(b,l,a);
            b[pos]=a;
            if(pos==l) l++;
        }
        printf("%d\n",l);
    }
}

int divide_ffb(int b[],int l,int key)
{
    int mid,s=0,e=l-1;
    if(key>b[l-1]) return l;
    while(s<e)
    {
        mid=s+(e-s)/2;
        if(b[mid]<=key) s=mid+1;
        else e=mid;
    }
    return s;
}