var
n,i,l,r,x,mid:longint;
f:array[0..10000]of longint;
begin
assign(input,'tahort.in');
assign(output,'tahort.out');
reset(input);
rewrite(output);
read(n);
for i:=1 to n do
begin
read(x);
l:=1;r:=f[0];
while l<r do
begin
mid:=(l+r)shr 1;
if f[mid]<x then
l:=mid+1 else r:=mid;
end;
if ((l>=r)and(x>f[f[0]]))then
begin
f[0]:=f[0]+1;
f[f[0]]:=x;
l:=f[0];
end else
if x<f[l] then
f[l]:=x;
end;
write(f[0]);
close(input);
close(output);
end.