program cch(input,output);
var
i,j,n,ans,ch,q:integer;
a:array[1..10000] of string;
father:array[0..10000] of integer;
child:array[0..10000,0..100] of integer;
procedure search(k:integer);
var
i:integer;
begin
if ch>ans then ans:=ch;
for i:=1 to child[k,0] do
begin
inc(ch);
search(child[k,i]);
dec(ch);
end;
end;
begin
assign(input,'link.in');
assign(output,'link.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do child[i,0]:=0;
for i:=1 to n do
begin
j:=i-1;
while (j>0)and(pos(a[j],a[i])=0) do dec(j);
father[i]:=j;
inc(child[j,0]);
child[j,child[j,0]]:=i;
end;
ans:=0;
for i:=1 to n do
if father[i]=0 then
begin
ch:=1;
search(i);
end;
write(ans);
close(input);
close(output);
end.