#include<cstdio>
#include<cstring>
#include<iostream>
#define mem(arr,arl) memset(arr,arl,siae)
using namespace std;
const int maxn=100010;
int len[maxn],h[maxn],ge[maxn];
int read(){
int f=1,x=0;
char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if (ch=='-')f=-1;
else x=ch-'0';
ch=getchar();
while (ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
int Find(int x,int l,int r){
if(r<l)return l;
int mid=(l+r)>>1;
if(len[mid]>x)Find(x,mid+1,r);
else Find(x,l,mid-1);
}
int MY(){
freopen("lunch.in","r",stdin);
freopen("lunch.out","w",stdout);
len[0]=0x7f7f7f;
int p;p=read();
for(int i=1;i<=p;i++){
h[i]=read();
if(!h[i])continue;
int z=Find(h[i],0,p);
ge[i]=z;
len[z]=h[i];
}
int ans=0;
for(int i=1;i<=p;i++)if(ans<ge[i])ans=ge[i];
printf("%d\n",ans);
return 0;
}
int YOU=MY();
int main(){;}