program punch;
var
sz:array[0..10000]of record
b,e,c:longint;
end;
hx:array[1..10000]of 0..1;
n,m,i,j,t1,t2,t:longint;
begin
fillchar(hx,sizeof(hx),0);
assign(input,'punch.in');
assign(output,'punch.out');
reset(input);
rewrite(output);
readln(n);
m:=0;
for i:=1 to n do
begin
readln(t1,t2);
t:=0;
while t<m do
begin
t:=t+1;
if (sz[t].b>=t1)and(sz[t].e<=t2) then begin
sz[t]:=sz[m];
m:=m-1;
t:=t-1;
end
else begin
if (sz[t].b<t1)and(sz[t].e>t2) then begin
m:=m+1;
sz[m]:=sz[t];
sz[t].e:=t1;
sz[m].b:=t2;
end
else begin
if (t1<=sz[t].b)and(sz[t].b<=t2)and(t2<sz[t].e) then begin
sz[t].b:=t2;
end
else begin
if (sz[t].b<t1)and(t1<=sz[t].e)and(sz[t].e<=t2) then begin
sz[t].e:=t1;
end;
end;
end;
end;
end;
m:=m+1;
sz[m].b:=t1;
sz[m].e:=t2;
sz[m].c:=i;
end;
t:=0;
for i:=1 to m do
if (hx[sz[i].c]=0)and(sz[i].b<sz[i].e) then begin
t:=t+1;
hx[sz[i].c]:=1;
end;
writeln(t);
close(input);
close(output);
end.