program ex;
type
ss=array[1..10000]of longint;
sz=array[1..10000]of boolean;
var
f1,f2:text;
a,b:ss;
c:sz;
n,t:integer;
i,j:longint;
begin
assign(f1,'punch.in');
assign(f2,'punch.out');
reset(f1);
rewrite(f2);
readln(f1,n);
t:=0;
for i:=1 to n do
begin
readln(f1,a[i],b[i]);
for j:=1 to i-1 do
if c[j]=true then
begin
if (a[i]<=a[j])and(b[i]>a[j])and(b[i]<b[j]) then a[j]:=b[i];
if (a[i]>a[j])and(a[i]<b[j])and(b[i]>=b[j]) then b[j]:=a[i];
if (a[i]<=a[j])and(b[i]>=b[j]) then
begin
c[j]:=false;
dec(t);
end;
end;
c[i]:=true;
inc(t);
end;
writeln(f2,t);
close(f1);
close(f2);
end.