{$DEFINE DEBUG}
{$DEFINE DMI}
{$DEFINE DO0}
{$IFDEF DEBUG}
{$B-,I+,N+,O-,Q-,R+,S+} {No overflow check!}
{$ELSE}
{$B-,I-,N+,O+,Q-,R-,S-}
{$ENDIF}
{$APPTYPE CONSOLE}
Program JurySol;
uses SysUtils;
const TaskName = 'cycles';
 MinN = 1; MaxN = 2500; MinR = 0; MaxR = 2500;
var i, j, k, n: Integer;
 a: array [1..MaxN, 0..MaxN] of Cardinal;
 b, e, s, t: array [1..MaxN] of Integer;
 l, m: Cardinal;

BEGIN
 reset (input, TaskName + '.in');
 rewrite (output, TaskName + '.out');
{$IFDEF DMI} repeat {$ENDIF}
 assert (NOT seekeoln);
 read (n);
 assert ((n >= MinN) AND (n <= MaxN));
 assert (seekeoln);
 readln;
 for i := 1 to n do begin
  assert (NOT seekeoln);
  read (b[i]);
  assert ((b[i] >= 1 - i) AND (b[i] <= MaxR));
  assert (NOT seekeoln);
  read (e[i]);
  assert ((e[i] >= MinR) AND (e[i] <= MaxR));
  assert (seekeoln);
  readln;
 end;

 for i := 1 to n do
  if b[i] < 0 then
   if e[-b[i]] > e[i] then
    e[-b[i]] := e[i];

 for i := 1 to n do
  if b[i] < 0 then begin
   t[i] := -b[i];
   s[i] := s[t[i]];
  end else begin
   t[i] := 0;
   s[i] := b[i];
  end;

 for i := 1 to n do
  for j := s[i] to e[i] do
   a[i][j] := 1;

 m := 1;
 for i := 1 to n do
  if s[i] > e[i] then begin
   m := 0;
   break;
  end;

 for i := n downto 1 do begin
  for j := e[i] - 1 downto s[i] do
   inc (a[i][j], a[i][j + 1]);
  if t[i] = 0 then begin
   m := m * a[i][s[i]];
  end else begin
   k := t[i];
   for j := e[k] downto s[k] do
    a[k][j] := a[k][j] * a[i][j];
  end;
 end;

 writeln (m);
{$IFDEF DMI} until seekeof; {$ENDIF}
 assert (seekeof);
END.
