#include<bits/stdc++.h>

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 310, Mod = 1e9 + 7;
void pls(int &x, int y) {
	x += y;
	if (x >= Mod) x -= Mod;
}
bool vis[N << 1], flg[N << 1];
int f[N << 1][N][N], a[N << 1];
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= 2 * n; i++) a[i] = gi<int>();
	int cnt1 = 0, cnt2 = 0;
	for (int i = 1; i < 2 * n; i += 2) {
		if (a[i] == a[i + 1])
			cnt2++;
		else {
			if (a[i] > a[i + 1]) swap(a[i], a[i + 1]);
			if (a[i] == -1) cnt1++, flg[a[i + 1]] = 1;			
			else vis[a[i]] = vis[a[i + 1]] = 1;
		}
	}
	int m = 0;
	f[0][0][0] = 1;
	for (int i = 2 * n; i >= 1; i--)
		if (!vis[i]) {
			m++;
			if (!flg[i]) {
				for (int j = 0; j <= cnt1 + cnt2; j++)
					for (int k = 0; k <= cnt1; k++) {
						pls(f[m][j + 1][k], f[m - 1][j][k]);
						if (j) pls(f[m][j - 1][k], f[m - 1][j][k]);
						if (k) pls(f[m][j][k - 1], 1ll * k * f[m - 1][j][k] % Mod);
					}
			}
			else {
				for (int j = 0; j <= cnt1 + cnt2; j++)
					for (int k = 0; k <= cnt1; k++) {
						pls(f[m][j][k + 1], f[m - 1][j][k]);
						if (j) pls(f[m][j - 1][k], f[m - 1][j][k]);
					}
			}
		}
	int ans = f[m][0][0];
	for (int i = 1; i <= cnt2; i++)
		ans = 1ll * ans * i % Mod;
	printf("%d\n", ans);
	return 0;
}
