program df;
var
f1,f2:text;
a:array[1..10000000]of integer;
b:array[1..10000] of integer;
k,n,i,j,g,h,x,y:longint;
begin
assign(f1,'punch.in');
assign(f2,'punch.out');
reset(f1);
rewrite(f2);
readln(f1,n);
x:=maxint;
y:=0;k:=0;
for i:= 1to n do begin readln(f1,g,h);
if g<x then x:=g;
if h>y then y:=h;
for j:= g to h do a[j]:=i;end;
for i:= x to y do inc(b[a[i]]);
for i:= 1to n do if b[i]<>0 then inc(k);
writeln(f2,k);
close(f1);
close(f2);
end.