program link;
const
max=10000;
type
sz=array[1..max]of string;
var
f1,f2:text;
n,ans,top:integer;
a,b:sz;
procedure ini;
var
i:integer;
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]);
for i:=1 to max do b[i]:='';
close(f1);
b[1]:=a[1];
top:=1;
ans:=0;
end;
function pan(s:string):boolean;
var
i:integer;
begin
pan:=true;
i:=pos(b[top],s);
if i<>1 then pan:=false;
end;
procedure main;
var
i,j:integer;
s:string;
begin
for i:=2 to n do
if pan(a[i]) then begin
inc(top);
b[top]:=a[i];
end else begin
if top>ans then begin ans:=top end;
dec(top);
while(top>=1)and(pan(a[i])=false)do dec(top);
inc(top);
b[top]:=a[i];
end;
if top>ans then ans:=top;
end;
begin
ini;
main;
write(f2,ans);
close(f2);
end.