program ex(f1,f2);
type
zn=array [1..10000] of string;
var
a:zn; i,j,k,p,m,n,l,max:longint;
f1,f2:text; flag:boolean; c:zn;
begin
assign(f1,'link.in'); reset(f1);
assign(f2,'link.out'); rewrite(f2);
readln(f1,n);
for i:=1 to n do readln(f1,a[i]);
c[1]:=a[1]; l:=1; max:=0;
for i:=2 to n do
begin
flag:=true;
while flag do
begin
if pos(c[l],a[i])<>0 then
begin
inc(l);
c[l]:=a[i];
flag:=false;
end
else
begin
if l>max then max:=l;
dec(l);
end;
end;
end;
if l>max then max:=l;
writeln(f2,max);
close(f1);
close(f2);
end.