#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7;
bool gone[605], empty[605];
ll dp[305][305], ndp[305][305];
void add(ll& x, ll y) {
	x += y;
	if (x >= MOD) x -= MOD;
}
int main() {
	int n;
	scanf("%d", &n);
	int slots = 0;
	ll mult = 1;
	for (int i = 0; i < n; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a == -1 && b == -1) {
			++slots;
			mult = mult * slots % MOD;
		} else if (a == -1 || b == -1) {
			empty[a + b + 1] = true;
		} else {
			gone[a] = gone[b] = true;
		}
	}
	dp[0][0] = 1;
	for (int i = 2 * n; i >= 1; --i) {
		if (gone[i]) continue;
		memset(ndp, 0, sizeof(ndp));
		for (int j = 0; j <= n; ++j) // # of unused numbers
			for (int k = 0; k <= n; ++k) { // # of unput cells
				if (empty[i]) {
					// Grab unused number from before
					if (j) add(ndp[j - 1][k], dp[j][k]);
					// Leave as unput
					if (k < n) add(ndp[j][k + 1], dp[j][k]);
				} else {
					// Grab unused number from before
					if (j) add(ndp[j - 1][k], dp[j][k]);
					// Put on one of the unput cells
					if (k) add(ndp[j][k - 1], k * dp[j][k] % MOD);
					// Leave as unused
					if (j < n) add(ndp[j + 1][k], dp[j][k]);
				}
			}
		swap(dp, ndp);
	}
	ll ans = dp[0][0] * mult % MOD;
	printf("%lld\n", ans);
}
