program MayLava;
var
s:array[0..10000]of string;
a:array[0..10000]of longint;
n:longint;
procedure start;
var
f:text;
i:longint;
begin
assign(f,'link.in');
reset(f);
readln(f,n);
for i:=1 to n do begin
readln(f,s[i]);
a[i]:=1;
end;
close(f);
end;
procedure main;
var
i,j,max:longint;
begin
for i:=2 to n do begin
max:=0;
for j:=i-1 downto 1 do
if (pos(s[j],s[i])=1) and (a[j]>max) then max:=a[j];
a[i]:=a[i]+max;
end;
end;
procedure print;
var
f:text;
i,max:longint;
begin
max:=0;
for i:=1 to n do
if a[i]>max then max:=a[i];
assign(f,'link.out');
rewrite(f);
writeln(f,max);
close(f);
end;
BEGIN
start;
main;
print;
END.