#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int N = 305;
const int MOD = 1e9 + 7;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

inline void Inc(int &x, int y) {
	x += y; if (x >= MOD) x -= MOD;
}

int n, nn, a[N<<1], vis[N<<1], type[N<<1];
int t1, t2, dp[2][N][N];

void init() {
	read(n); nn = n<<1;
	for (int i=1;i<=nn;++i) {
		read(a[i]);
	}
	for (int i=1;i<=nn;i+=2) {
		if (a[i] == -1 && a[i+1] == -1) {
			++t1;
		} else if (a[i] > 0 && a[i+1] > 0) {
			vis[a[i]] = vis[a[i+1]] = 1;
		} else {
			++t2;
			if (a[i] > 0) type[a[i]] = 1;
			else type[a[i+1]] = 1;
		}
	}
}

void solve() {
	dp[0][0][0] = 1;
	int pre = 0, cur = 1;
	for (int i=nn;i>=1;--i) {
		if (vis[i]) continue;
		mset(dp[cur], 0);
		for (int j=0;j<=t1+t2;++j) {
			for (int k=0;k<=t1+t2;++k) {
				if (type[i]) {
					Inc(dp[cur][j][k+1], dp[pre][j][k]);
					if (j) Inc(dp[cur][j-1][k], dp[pre][j][k]);
				} else {
					Inc(dp[cur][j+1][k], dp[pre][j][k]);
					if (j) Inc(dp[cur][j-1][k], dp[pre][j][k]);
					if (k) Inc(dp[cur][j][k-1], 1LL * dp[pre][j][k] * k % MOD);
				}
			}
		}
		pre = cur; cur ^= 1;
	}
	int ans = dp[pre][0][0];
	for (int i=1;i<=t1;++i) {
		ans = 1LL * ans * i % MOD;
	}
	printf("%d\n", ans);
}

int main() {
	init();
	solve();
	return 0;
}
