#include <bits/stdc++.h>
using namespace std;

const int N = 310;
const int M = N << 1;
const int Mod = 1e9 + 7;
int n, m, ans, cnt, tot, a[M], b[M], c[M], f[M][N][N];

inline int dec(int x) {return x < 0 ? x + Mod : x;}
inline int inc(int x) {return x >= Mod ? x - Mod : x;}

template <class T> inline void in(T &x) {
	x = 0; int f = 0; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x = f ? -x : x;
}

int main() {
	in(n), m = n << 1;
	for (int i = 1; i <= m; ++i) in(a[i]);
	for (int i = 1; i <= m; i += 2)
		if (~a[i] && ~a[i + 1]) b[a[i]] = b[a[i + 1]] = 2;
		else if (~a[i]) b[a[i]] = 1;
		else if (~a[i + 1]) b[a[i + 1]] = 1;
		else ++cnt;
	for (int i = 1; i <= m; ++i)
		if (b[i] & 1) c[++tot] = 1;
		else if (!b[i]) c[++tot] = 0;
	f[tot][0][0] = 1;
	for (int i = tot; i; --i)
		for (int j = 0; j <= tot && j <= n; ++j)
			for (int k = 0; k <= tot && k <= n; ++k) if (c[i]) {
				f[i - 1][j + 1][k] = inc(f[i - 1][j + 1][k] + f[i][j][k]);
				if (k) f[i - 1][j][k - 1] = inc(f[i - 1][j][k - 1] + f[i][j][k]);
			} else {
				f[i - 1][j][k + 1] = inc(f[i - 1][j][k + 1] + f[i][j][k]);
				if (k) f[i - 1][j][k - 1] = inc(f[i - 1][j][k - 1] + f[i][j][k]);
				if (j) f[i - 1][j - 1][k] = inc(f[i - 1][j - 1][k] + 1LL * f[i][j][k] * j % Mod);
			}
	ans = f[0][0][0];
	for (int i = 1; i <= cnt; ++i) ans = 1LL * ans * i % Mod;
	printf("%d\n", ans);
	return 0;
}