program link(input,output);
var
sta:array[1..10000]of string;
top,i,n,max: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);
top:=0; max:=0;
readln(st);
push(st);
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;
write(max);
close(input);close(output);
end.