program df;
var
f1,f2:text;
s:array[1..10000]of string;
f:array[1..10000]of string;
s1:string;
p,ans,n,i,j,k: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,s[i]);
f[1]:=s[1];p:=1;
for i:= 2 to n do begin
s1:=copy(s[i],1,length(f[p]));
if s1=f[p] then begin
inc(p);
if ans<p then ans:=p;
f[p]:=s[i];
end
else begin
for j:=p downto 1 do begin
s1:=copy(s[i],1,length(f[j-1]));
if s1=f[j-1]then begin f[j]:=s[i];p:=j;break;end;
if j=2 then begin f[1]:=s[i];p:=1;end;
end;
end;
end;
writeln(f2,ans);
close(f1);
close(f2);
end.