{$Q+,R+,I+,O-}

uses SysUtils,Math;

const FileName = 'cycles';
      MaxN = 1000;
      MaxV = 1000;


var i,j,k,n:integer;
    l,r:array[1..MaxN] of integer;
    a,c:array[1..MaxN,0..MaxV] of int64;
    b:array[1..MaxN] of int64;
    s,ss:int64;

begin
  reset(input,FileName+'.in');
  rewrite(output,FileName+'.out');
  while not seekeof do begin
    read(n);
    assert(n<=MaxN);
    for i:=1 to n do begin
      read(l[i],r[i]);
      assert(-l[i]<i);
      assert(l[i]<maxV);
      assert(r[i]>=0);
      assert(r[i]<maxV);
    end;
    fillchar(a,sizeof(a),0);
    fillchar(b,sizeof(b),0);
    fillchar(c,sizeof(c),0);
    for i:=1 to n do
      if l[i] >=0 then
        for j:=l[i] to r[i] do c[i][j]:=1;
    for i:=1 to n do 
      if l[i]>=0 then
        b[i]:=1;
    for i:=1 to n do begin
      for j:=0 to MaxV do a[i][j]:=c[i][j]*b[i];
      s:=0;
      for j:=0 to MaxV do s:=s+a[i][j];
      for j:=i+1 to n do begin
        if l[j] <> - i then b[j]:=b[j]*s
        else begin
          b[j]:=1;
          ss:=0;
          for k:=0 to MaxV do begin
            if k>r[j] then break;
            ss:=ss+a[i][k];
            c[j][k]:=ss
          end;
        end;
      end;
    end;
    s:=0;
    for i:=0 to MaxV do s:=s+a[n][i];
    writeln(s);
  end; 
end.


