program link;
var
stack:array[1..10000]of string;
n,i,k,max:longint;
s:string;
begin
assign(input,'link.in');
reset(input);
assign(output,'link.out');
rewrite(output);
readln(n);
k:=0; max:=0;
for i:=1 to n do
begin
readln(s);
if (k=0) or (pos(stack[k],s)=1) then
begin
inc(k);
stack[k]:=s;
end
else
begin
if max<k then max:=k;
while (pos(stack[k],s)<>1)and(k>0) do
begin
stack[k]:='';
dec(k);
end;
stack[k+1]:=s;
inc(k);
end;
end;
if k>max then max:=k;
writeln(max);
close(input);
close(output);
end.