program EmberAsh;
var
a:array[0..10000000]of longint;
b:array[0..10000000]of boolean;
i,j,k,t1,t2,n,m,min,max:longint;
fin,fout:text;
BEGIN
assign(fin,'punch.in');reset(fin);
assign(fout,'punch.out');rewrite(fout);
readln(fin,n);
min:=maxlongint;max:=0;
for i:=1 to n do
begin
inc(k);
readln(fin,t1,t2);
if t1<min then min:=t1;
if t2>max then max:=t2;
for j:=t1 to t2 do
a[j]:=k;
end;
for i:=min to max do
if b[a[i]]=false then
begin
inc(m);
b[a[i]]:=true;
end;
writeln(fout,m);
close(fin);close(fout);
END.