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

const int maxn(605);
const int mod(1e9 + 7);

inline void Inc(int &x, const int y) {
    x = x + y >= mod ? x + y - mod : x + y;
}

inline void Dec(int &x, const int y) {
    x = x - y < 0 ? x - y + mod : x - y;
}

inline int Add(const int x, const int y) {
    return x + y >= mod ? x + y - mod : x + y;
}

inline int Sub(const int x, const int y) {
    return x - y < 0 ? x - y + mod : x - y;
}

inline int Pow(ll x, int y) {
    int ret = 1;
    for (; y; y >>= 1, x = x * x % mod)
        if (y & 1) ret = ret * x % mod;
    return ret;
}

int a[maxn], n, op[maxn], f[maxn][maxn][maxn], ans;

int main() {
	int i, j, k, c1, c2;
	scanf("%d", &n);
	for (i = 1, j = n << 1; i <= j; ++i) scanf("%d", &a[i]);
	for (i = 1; i <= n; ++i) {
		if (a[2 * i - 1] != -1) op[a[2 * i - 1]] = a[i << 1];
		if (a[i << 1] != -1) op[a[i << 1]] = a[2 * i - 1];
	}
	f[n * 2 + 1][0][0] = 1, c1 = 0, c2 = 0;
	for (i = n << 1; i; --i) {
		op[i] ? ++c1 : ++c2;
		if (op[i] > 0) {  memcpy(f[i], f[i + 1], sizeof(f[i])); continue;  }
		for (j = 0; j <= c1; ++j)
			for (k = 0; k <= c2; ++k)
				if (f[i + 1][j][k]) {
					if (!op[i]) {
						Inc(f[i][j][k + 1], f[i + 1][j][k]);
						if (j) Inc(f[i][j - 1][k], (ll)f[i + 1][j][k] * j % mod);
						if (k) Inc(f[i][j][k - 1], f[i + 1][j][k]);
					}
					else {
						Inc(f[i][j + 1][k], f[i + 1][j][k]);
						if (k) Inc(f[i][j][k - 1], f[i + 1][j][k]);
					}
				}
	}
	for (c2 = 0, i = 1; i <= n; ++i) c2 += a[i << 1] == -1 && a[i * 2 - 1] == -1;
	for (ans = f[1][0][0], i = 1; i <= c2; ++i) ans = (ll)ans * i % mod;
	printf("%d\n", ans);
	return 0;
}