#include<cstdio>
typedef long long LL;
LL a[10010],ans=0,n;
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
LL x; scanf("%lld",&x);
if(x==0) continue;
LL l=1,r=ans;
while(l<=r)
{
LL mid=(l+r)/2;
if(a[mid]==x) { l=mid; break; }
else if(a[mid]>x) l=mid+1;
else r=mid-1;
}
if(l<=ans) a[l]=x;
else a[++ans]=x;
}
printf("%d",ans);
return 0;
}