program punch;
type
fxz1=record left,right:longint;end;
fxz2=array[1..10000] of fxz1;
fxz3=array[0..100000000] of boolean;
var
f1,f2:text;
a:fxz3;
card:fxz2;
s:fxz1;
j,i,n,ans:longint;
f:boolean;
begin
assign(f1,'punch.in');
assign(f2,'punch.out');
reset(f1);rewrite(f2);
readln(f1,n);
for i:=1 to n do
begin
readln(f1,card[i].left,card[i].right);
dec(card[i].right);
end;ans:=0;
for i:=n downto 1 do
begin
f:=true;
for j:=card[i].left to card[i].right do
begin
if (f)and(not a[j]) then begin f:=false;inc(ans);end;
a[j]:=true;
end;
end;
writeln(f2,ans);
close(f1);close(f2);
end.