program punch;
var n:longint;
card:array[1..10000,1..2] of longint;
hash:array[1..10000] of boolean;
sy:longint;
x1,x2:longint;
pi,po:text;
jg:=longint;
p:boolean;
begin
assign(pi,'punch.in');
reset(pi);
readln(pi,n);
assign(po,'punch.out');
rewrite(po);
sy:=n;
jg:=0;
fillchar(hash,sizeof(hash),false);
for x1:=1 to n do
readln(pi,card[x1,1],card[x1,2]);
close(pi);
for x1:=n downto 1 do
begin
if sy=0 then
begin
writeln(po,jg);
halt;
end
else
begin
p:=false;
for x2:=card[x1,1]+1 to card[x1,2] do
if hash[x2]=false then
begin
p:=true;
hash[x2]:=true;
end;
if p=true then inc(jg);
end;
end;
writeln(po,jg);
close(po);
end.