#include <bits/stdc++.h>

const int MAXN = 310, MOD = 1e9 + 7;
inline int mul(int x, int y) { return 1LL * x * y % MOD; }
inline void Add(int &x, int y) { (x += y) >= MOD && (x -= MOD); }
inline void Mul(int &x, int y) { x = 1LL * x * y % MOD; }

int n, m, tot, QAQ;
int a[MAXN * 2], b[MAXN * 2], c[MAXN * 2], dp[MAXN * 2][MAXN][MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n * 2; ++i) scanf("%d", a + i);
	for (int i = 1; i <= n * 2; i += 2)
		if (a[i] == -1 || a[i + 1] == -1) {
			++m;
			if (~a[i]) b[a[i]] = 1;
			else if (~a[i + 1]) b[a[i + 1]] = 1;
			else ++QAQ;
		} else b[a[i]] = b[a[i + 1]] = -1;
	for (int i = 1; i <= n * 2; ++i) if (~b[i]) c[++tot] = b[i];
	dp[m * 2 + 1][0][0] = 1;
	for (int i = 1; i <= QAQ; ++i) Mul(dp[m * 2 + 1][0][0], i);
	for (int i = m * 2; i; --i)
		for (int j = 0; j <= m; ++j)
			for (int k = 0; j + k <= m; ++k) if (c[i]) {
				if (j + k < m) Add(dp[i][j + 1][k], dp[i + 1][j][k]);
				if (k) Add(dp[i][j][k - 1], dp[i + 1][j][k]);
			} else {
				if (j + k < m) Add(dp[i][j][k + 1], dp[i + 1][j][k]);
				if (j) Add(dp[i][j - 1][k], mul(dp[i + 1][j][k], j));
				if (k) Add(dp[i][j][k - 1], dp[i + 1][j][k]);
			}
	printf("%d\n", dp[1][0][0]);
	return 0;
}