program bing;
var
f1,f2:text;
n,i,k,max:longint;
s:string;
a:array[0..10000] of string;
begin
assign(f1,'link.in');reset(f1);
assign(f2,'link.out');rewrite(f2);
readln(F1,n);
max:=0;
readln(f1,s);
a[1]:=s;
k:=1;
for i:=2 to n do
begin
readln(f1,s);
if pos(a[k],s)=1 then
begin inc(k);
a[k]:=s;end
else
begin
while pos(a[k],s)<>1 do dec(k);
inc(k);a[k]:=s;
end;
if k>max then max:=k;
end;
write(f2,max);
close(f1);close(f2);
end.