program link;
Type
fxz1=array[1..10000] of string;
fxz2=array[1..10000] of longint;
var
f1,f2:text;
i,j,max,n,f:longint;
a:fxz1;
ans:fxz2;
begin
assign(f1,'link.in');
assign(f2,'link.out');
reset(f1);rewrite(f2);
readln(f1,n);
for i:=1 to n do
begin
readln(f1,a[i]);
ans[i]:=1;
end; max:=1;
for i:=2 to n do
begin
for j:=i-1 downto 1 do
begin if a[j][1]<>a[i][1] then break;
f:=pos(a[j],a[i]);
if (f<>0) then if ans[j]+1>ans[i] then ans[i]:=ans[j]+1;
end;
if ans[i]>max then max:=ans[i];
end;
writeln(f2,max);
close(f1);close(f2);
end.