program cch(input,output);
const
maxs=1000000000;
var
min,max,n,i,x,y,j,ans:longint;
flag:array[1..100000] of boolean;
a:array[0..100000] of integer;
begin
assign(input,'punch.in');
assign(output,'punch.out');
reset(input);
rewrite(output);
readln(n);
min:=maxs; max:=0;
for i:=1 to n do
begin
readln(x,y);
if x+1<min then min:=x+1;
if y>max then max:=y;
for j:=x+1 to y do
a[j]:=i;
end;
for i:=1 to n do flag[i]:=true;
ans:=0;
for i:=min to max do
if flag[a[i]] then
begin
inc(ans);
flag[a[i]]:=false;
end;
write(ans);
close(input);
close(output);
end.