program waterfire;
const
fin='link.in';
fout='link.out';
var
n,i,j:longint;
ss:array[0..10000] of string;
ans:array[0..10000] of longint;
max:longint;
f,g:text;
BEGIN
max:=-maxint;
assign(f,fin);reset(f);
assign(g,fout);rewrite(g);
readln(f,n);
for i:=1 to n do begin
readln(f,ss[i]);
ans[i]:=1;
end;
for i:=n downto 1 do
for j:=i-1 downto 1 do
if (pos(ss[j],ss[i])<>0)and(ans[i]>=ans[j])
then inc(ans[j]);
for i:=1 to n do
if ans[i]>max then max:=ans[i];
write(g,max);
close(f);close(g);
end.