program ex;
type
ss=array[1..10000]of string;
var
a,cup:ss;
f1,f2:text;
n,tot,c:integer;
procedure init;
var
i:integer;
begin
assign(f1,'link.in');
assign(f2,'link.out');
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,a[i]);
close(f1);
end;
procedure main;
var
i:integer;
begin
c:=1;
cup[c]:=a[c];
i:=2;
while i<=n do
begin
if pos(cup[c],a[i])<>0 then
begin
inc(c);
if c>tot then tot:=c;
cup[c]:=a[i];
inc(i);
end
else begin
if (pos(cup[c],a[i])=0)and(c>1) then
begin
cup[c]:='';
dec(c);
end;
if c=1 then cup[c]:=a[i];
end;
end;
end;
begin
init;
main;
writeln(f2,tot);
close(f2);
end.