var
i,top,l,r,x,now,n:longint;
q,a:array[0..1000000]of longint;
function erfen(l,r:longint):longint;
var
mid:longint;
begin
if l=r then exit(l);
mid:=(l+r) div 2;
if a[mid]>now then erfen(mid+1,r)
else erfen(l,mid);
end;
begin
assign(input,'lunch.in'); reset(input);
assign(output,'lunch.out'); rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
top:=0;
q[0]:=maxlongint;
for i:=1 to n do
if a[i]<>0 then
begin
if a[i]<q[top] then
begin
inc(top);
q[top]:=a[i];
end
else begin
l:=1;
r:=top;
now:=a[i];
x:=erfen(l,r);
q[x]:=a[i];
end;
end;
writeln(top);
close(input);
close(output);
end.