program punch;
var
n:integer;
a,b,s:array[1..10000] of longint;
z:array[1..100000000] of longint;
m,i,j:longint;
fin,fout:text;
procedure init;
var
i,j:longint;
begin
readln(fin,n);
for i:=1 to n do
readln(fin,a[i],b[i]);
fillchar(s,sizeof(s),0);
fillchar(z,sizeof(z),0);
end;
end;
begin
assign(fin,'punch.in');
assign(fout,'punch.out');
reset(fin);
rewrite(fout);
init;
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;
write(fout,m);
close(fin);
close(fout);
end.