#include <fstream>
using namespace std;
int a[100001]={0},b[100001]={0};
int main()
{
ifstream in("lunch.in");
ofstream out("lunch.out");
int n,i,j;
int mid,head,tail;
int ans=0;
in>>n;
for (i=1;i<=n;i++)
in>>a[i];
for (i=n;i>=1;i--)
{
if (a[i]==0)
continue;
head=1;
tail=ans;
while (head<=tail)
{
mid=(head+tail)/2;
if (b[mid]<a[i])
head=mid+1;
else
tail=mid-1;
}
if (head>ans)
ans++;
b[head]=a[i];
}
out<<ans<<endl;
return 0;
}