program ex;
type
ss=array[1..10000]of string;
sz=array[1..10000]of boolean;
var
a:ss;
b:sz;
f1,f2:text;
n,tot:integer;
procedure init;
var
i:integer;
begin
assign(f1,'link.in');
assign(f2,'link.out');
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,a[i]);
close(f1);
for i:=1 to n do
b[i]:=true;
end;
procedure try(s:string;t:integer);
var
i,j:integer;
s1:string;
begin
if t>tot then tot:=t;
for i:=1 to n do
if (pos(s,a[i])<>0)and(b[i]=true) then
begin
inc(t);
s1:=a[i];
b[i]:=false;
try(s1,t);
dec(t);
b[i]:=true;
end;
end;
begin
init;
try(a[1],0);
writeln(f2,tot);
close(f2);
end.