var
i,a,n,f0:longint;
f:array[0..1000000]of longint;
function find(l,r,a:longint):longint;
var p:longint;
begin
while r-l>1 do begin
p:=(l+r)div 2;
if f[p]=a then exit(p);
if f[p]>a then r:=p else l:=p;
end;
find:=r;
end;
begin
assign(input,'lis1.in');
reset(input);
assign(output,'lis1.out');
rewrite(output);
readln(n);
for i:=1 to n do begin
read(a);
if a>f[f0] then begin
inc(f0);
f[f0]:=a;
end
else f[find(0,f0,a)]:=a;
end;
writeln(f0);
close(input);
close(output);
end.