program bly(input,output);
var
a,st:array[1..10000] of string;
long,max:integer;
i,j,n:integer;
f1,f2:text;
procedure input0(s:string);
begin
inc(long);
a[long]:=s;
end;
procedure output0;
begin
a[long]:='';
dec(long);
end;
begin
assign(f1,'link.in');
reset(f1);
readln(f1,n);
for i:=1 to n do readln(f1,st[i]);
close(f1);
long:=0;
for i:=1 to n do begin
if long=0 then input0(st[i])
else begin
if pos(a[long],st[i])=1 then input0(st[i]);
if pos(a[long],st[i])=0 then begin
repeat
output0;
until pos(a[long],st[i])=1;
input0(st[i]);
end;
end;
if long>max then max:=long;
end;
assign(f2,'link.out');
rewrite(f2);
writeln(f2,max);
close(f2);
end.