program link;
const
fin='link.in';
fou='link.out';
var
f:array[1..10000]of longint;
st:array[1..10000]of string;
max,p,n,i,j:longint;
f1,f2:text;
procedure init;
begin
assign(f1,fin);
assign(f2,fou);
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,st[i]);
for i:=1 to n do
f[i]:=1;
end;
begin
init;
for i:=1 to n do
begin
j:=i-1;
while (j>0)and(st[j][1]=st[i][1])and(f[i]<=j) do
begin
p:=pos(st[j],st[i]);
if p<>0 then
if f[i]<f[j]+1 then f[i]:=f[j]+1;
dec(j);
end;
if max<f[i] then max:=f[i];
end;
write(f2,max);
close(f1); close(f2);
end.