program ooo;
var
i,j,m,n,k,max:longint;
a,aa:array[0..10002] of string;
t:text;
b,c:array[0..10002] of longint;
begin
assign(t,'link.in');
reset(t);
readln(t,n);
for i:=1 to n do
readln(t,a[i]);
close(t);
k:=0;
for i:=1 to n do
b[i]:=1;
for i:=1 to n do
for j:=1 to i-1 do
if (pos(a[j],a[i])<>0)and(b[j]>=b[i]) then
begin
b[i]:=b[j]+1;
c[i]:=j;
end;
max:=0;
for i:=1 to n do
if b[i]>max then max:=b[i];
assign(t,'link.out');
rewrite(t);
writeln(t,max);
close(t);
end.