program punch;
var
a:array[1..110000]of longint;
i,x,y,n,h:longint;
procedure go(x,y:longint);
var
i,j,k:longint;
Begin
i:=h; j:=h;
while (x<a[i])and(i>0) do i:=i-1;
i:=i+1;
if a[i-1]<>x then begin
if i<=h then for k:=h downto i do a[i+1]:=a[i];
a[i]:=x; h:=h+1;
end;
while (y<a[j])and(j>0) do j:=j-1;
j:=j+1;
if a[j-1]<>y then begin
if j<=h then for k:=h downto j do a[j+1]:=a[j];
a[j]:=y; h:=h+1;
end;
End;
Begin
assign(input,'punch.in');
assign(output,'punch.out');
reset(input); rewrite(output);
readln(n); h:=2;
readln(x,y);
a[1]:=x; a[2]:=y;
for i:=1 to n-1 do begin
readln(x,y);
go(x,y);
end;
writeln((h/2-1):0:0);
close(input); close(output);
End.