program ds;
var
s:array[1..10000] of string;
f:array[1..10000] of string;
n,i,j,p,ans:longint;
temp,temp1:string;
procedure chushi;
var input:text;
begin
assign(input,'link.in');
reset(input);
readln(input,n);
for i:=1 to n do
readln(input,s[i]);
close(input);
end;
procedure shuchu;
var output:text;
begin
assign(output,'link.out');
rewrite(output);
writeln(output,ans);
close(output);
end;
function max(a,b:longint):longint;
begin
if a>b then exit(a);
exit(b);
end;
begin
chushi;
f[1]:=s[1];p:=1;
for i:=2 to n do
begin
temp:=copy(s[i],1,length(f[p]));
if temp=f[p] then
begin
inc(p);
ans:=max(ans,p);
f[p]:=s[i];
end
else
begin
repeat
temp1:=copy(s[i],1,length(f[p-1]));
if (temp1=f[p-1]) then
begin
f[p]:=s[i];
break;
end;
dec(p);
if p=1 then
begin
f[p]:=s[i];
break;
end;
until 1<>1;
end;
end;
shuchu;
end.