#include <bits/stdc++.h>

using namespace std;

const int md = 1e9 + 7;

inline void add(int &x, int y) {
  x += y;
  if (x >= md) {
    x -= md;
  }
}

inline int mul(int x, int y) {
  return (long long) x * y % md;
}

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  scanf("%d", &n);
  vector<bool> used(n * 2);
  vector<bool> single(n * 2);
  int free = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (~x) {
      --x;
    }
    if (~y) {
      --y;
    }
    if (~max(x, y)) {
      if (~min(x, y)) {
        used[x] = used[y] = true;
      } else {
        single[max(x, y)] = true;
      }
    } else {
      ++free;
    }
  }
  vector<vector<int>> dp(n + 1, vector<int> (n * 2 + 1));
  dp[0][0] = 1;
  for (int i = n * 2 - 1; ~i; --i) {
    if (!used[i]) {
      vector<vector<int>> new_dp(n + 1, vector<int> (n * 2 + 1));
      for (int j = 0; j <= n; ++j) {
        for (int k = 0; k <= n * 2; ++k) {
          if (dp[j][k]) {
            if (single[i]) {
              add(new_dp[j + 1][k], dp[j][k]);
              if (k) {
                add(new_dp[j][k - 1], dp[j][k]);
              }
            } else {
              add(new_dp[j][k + 1], dp[j][k]);
              if (j) {
                add(new_dp[j - 1][k], mul(j, dp[j][k]));
              }
              if (k) {
                add(new_dp[j][k - 1], dp[j][k]);
              }
            }
          }
        }
      }
      swap(dp, new_dp);
    }
  }
  int answer = dp[0][0];
  for (int i = 1; i <= free; ++i) {
    answer = mul(answer, i);
  }
  printf("%d\n", answer);
  return 0;
}
