program link(input,output);
var
sta:array[1..10000]of string;
i,n,max,top:integer;
st:string;
procedure push(st:string);
begin
inc(top);
sta[top]:=st;
end;
procedure pop;
begin
dec(top);
end;
begin
assign(input,'link.in');assign(output,'link.out');
reset(input);rewrite(output);
readln(n);
readln(sta[1]);
top:=1;
max:=0;
for i:=2 to n do begin
readln(st);
if pos(sta[top],st)<>0 then push(st)
else begin
if top>max then max:=top;
repeat
pop;
until pos(sta[top],st)<>0;
push(st);
end;
end;
if top>max then max:=top;
write(max);
close(input);close(output);
end.