program bing;
var
f1,f2:text;
n:integer;
a,b,s:array[1..10000] of longint;
z:array[1..100000000] of longint;
m:longint;
procedure init;
var
i,j:longint;
begin
assign(f1,'punch.in');reset(f1);
assign(f2,'punch.out');rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,a[i],b[i]);
fillchar(s,sizeof(s),0);
fillchar(z,sizeof(z),0);
end;
procedure nb;
var
i,j:longint;
begin
m:=0;
for i:=1 to n do
begin
for j:=a[i]+1 to b[i] do
if z[j]<>i then
begin
if z[j]>0 then
begin
dec(s[z[j]]);
if s[z[j]]=0 then dec(m);
end;
z[j]:=i;
if s[i]=0 then inc(m);
inc(s[i]);
end;
end;
end;
begin
init;
nb;
write(f2,m);
close(f1);close(f2);
end.