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

uses SysUtils,Math;

const FileName = 'cycles';
      MaxN = 2500;
      MaxV = 2500;
var i,n:integer;
    d,l,r:array[1..MaxN] of integer;
    hh,a:array[1..MaxN,0..MaxV] of cardinal;
    e:array[1..MaxN,0..MaxV] of integer;
    s:cardinal;
    gone:array[1..MaxN] of boolean;



function poisk(v,k:integer):cardinal;
var i,j:integer;
    ss:cardinal;
begin
  if not gone[v] then begin
    for i:=0 to r[v] do begin
      ss:=1;
      for j:=1 to d[v] do begin
        ss:=ss*poisk(e[v][j],i);
      end;
      hh[v][i]:=ss;
    end;
    for i:=r[V]-1 downto 0 do
      hh[v,i]:=hh[v,i]+hh[v,i+1];
    for i:=r[v]+1 to MaxV do hh[v][i]:=0;
    for i:=0 to MaxV do a[v][i]:=hh[v][i];
  end;
  gone[v]:=true;
  poisk:=a[v][k];
end;
      

begin
  reset(input,FileName+'.in');
  rewrite(output,FileName+'.out');
  assert (not seekeoln); read(n);
  assert(n<=MaxN);
  assert (eoln); readln;
  for i:=1 to n do begin
    assert (not seekeoln); read (l[i]);
    assert (not seekeoln); read (r[i]);
    assert (eoln and not eof); readln;
    assert(-l[i]<i);
    assert(l[i]<=maxV);
    assert(r[i]>=0);
    assert(r[i]<=maxV);
  end;
  assert (eof);
  fillchar(d,sizeof(d),0);
  for i:=1 to n do
    if l[i]<0 then begin
      inc(d[-l[i]]);
      e[-l[i]][d[-l[i]]]:=i;
    end;
  s:=1;
  fillchar(gone,sizeof(gone),0);
  for i:=1 to n do
    if not gone[i] then begin
      s:=s*poisk(i,l[i]);
    end;
  writeln (s);
end.


