program ex(f1,f2);
type
zn=array [1..100010] of longint;
ka=array [0..1000010] of integer;
la=array [1..100010] of boolean;
var
head,tail:zn;
c:ka; flag:la;
f1,f2:text;
i,j,k,p,m,n,l,ans,max:longint;
begin
assign(f1,'punch.in'); reset(f1);
assign(f2,'punch.out'); rewrite(f2);
readln(f1,n); max:=0; ans:=0;
for i:=1 to n do flag[i]:=true;
for i:=1 to n do
begin
readln(f1,head[i],tail[i]);
if tail[i]>max then max:=tail[i];
for j:=head[i]+1 to tail[i] do
c[j]:=i;
end;
for i:=1 to max do
if (flag[c[i]])and(c[i]>=1) then
begin
inc(ans);
flag[c[i]]:=false;
end;
writeln(f2,ans);
close(f1);
close(f2);
end.