/**
 *    author:  tourist
 *    created: 29.12.2018 15:10:55       
**/
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int md = (int) 1e9 + 7;

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

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

const int N = 610;

int dp[N][N];
int new_dp[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    cin >> a[i];
    if (a[i] > 0) {
      a[i]--;
    }
  }
  vector<int> alive(2 * n, 1);
  int pairs = 0;
  int with_one = 0;
  for (int i = 0; i < n; i++) {
    if (a[2 * i] != -1 && a[2 * i + 1] != -1) {
      alive[a[2 * i]] = 0;
      alive[a[2 * i + 1]] = 0;
    }
    if (a[2 * i] == -1 && a[2 * i + 1] == -1) {
      pairs++;
    }
    if ((a[2 * i] == -1) != (a[2 * i + 1] == -1)) {
      with_one++;
    }
  }
  vector<int> present(2 * n, 0);
  for (int i = 0; i < 2 * n; i++) {
    if (a[i] != -1) {
      present[a[i]] = 1;
    }
  }
  dp[0][0] = 1;
  for (int i = 0; i < 2 * n; i++) {
    if (!alive[i]) {
      continue;
    }
    for (int have = 0; have <= 2 * n; have++) {
      for (int bal = 0; bal <= 2 * n; bal++) {
        new_dp[have][bal] = 0;
      }
    }
    for (int have = 0; have <= 2 * n; have++) {
      for (int bal = 0; bal <= 2 * n; bal++) {
        int ft = dp[have][bal];
        if (ft == 0) {
          continue;
        }
        if (present[i]) {
          if (have > 0) {
            add(new_dp[have - 1][bal], mul(ft, have));
          }
          add(new_dp[have][bal + 1], ft);
        } else {
          add(new_dp[have + 1][bal], ft);
          add(new_dp[have][bal + 1], ft);
          if (bal > 0) {
            add(new_dp[have][bal - 1], ft);
          }
        }
      }
    }
    for (int have = 0; have <= 2 * n; have++) {
      for (int bal = 0; bal <= 2 * n; bal++) {
        dp[have][bal] = new_dp[have][bal];
      }
    }
  }
  int ans = dp[0][0];
  for (int i = 1; i <= pairs; i++) {
    ans = mul(ans, i);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3200