#include<bits/stdc++.h>
#define maxn 100001
using namespace std;
int n,f[10001];
inline const void read(int &a)
{
a=0;
int k=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
k=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
a=(a<<1)+(a<<3)+c-'0';
c=getchar();
}
a*=k;
}
int find(int x,int l,int r)
{
if(l==r)
return l;
int mid=(l+r)/2;
if(f[mid]>x)
find(x,l,mid);
else find(x,mid+1,r);
}
int main()
{
//freopen("sort.in.txt","r",stdin);
//freopen("sort.out.txt","w",stdout);
read(n);
int ai;
for(int i=1;i<=n;i++)
{
read(ai);
if(f[f[0]]<=ai)
f[++f[0]]=ai;
else f[find(ai,1,f[0])]=ai;
}
cout<<f[0]<<endl;
return 0;
}