program bing;
var
f1,f2:text;
a:array[1..10000] of string;
b:array[1..10000] of longint;
max,n,i,j:longint;
begin
assign(f1,'link.in');reset(F1);
assign(F2,'link.out');rewrite(f2);
readln(f1,n);
for i:=1 to n do readln(f1,a[i]);
for i:=1 to n do b[i]:=1;
for i:=n downto 1 do
for j:=i-1 downto 1 do
if (pos(a[j],a[i])=1)and(b[i]+1>b[j]) then b[j]:=b[i]+1;
max:=0;
for i:=1 to n do if b[i]>max then max:=b[i];
write(F2,max);
close(f1);close(F2);
end.