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

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

const int N = 607, p = 1e9+7;
int f[N][N], g[N][N];
int a[N], b[N], n, ct;

inline void pls(int&x, const int y) {x = x+y < p ? x+y : x+y-p;}

int main() {
	read(n);
	for(int i=1,x,y;i<=n;++i) {
		read(x), read(y);
		if((~x) and (~y)) {b[x] = b[y] = 2; continue;}
		if(~x) {b[x] = 1; continue;}
		if(~y) {b[y] = 1; continue;}
		++ct;
	}
	int nn = 0;
	for(int i=1;i<=n+n;++i)
		if(b[i] != 2)
			a[++nn] = b[i];
	
	swap(n,nn);
	nn = min(n, nn);
	g[0][0] = 1;
	for(int i=n;i;--i) {
		swap(f, g);
		for(int j=0;j<=nn;++j)
		for(int k=0;k<=nn;++k)
			g[j][k] = 0;
		
		if(a[i])
			for(int j=0;j<=nn;++j)
			for(int k=0;k<=nn;++k) {
				pls(g[j][k+1], f[j][k]);
				if(j) pls(g[j-1][k], f[j][k]);
			}
		else
			for(int j=0;j<=nn;++j)
			for(int k=0;k<=nn;++k) {
				pls(g[j+1][k], f[j][k]);
				if(j) pls(g[j-1][k], f[j][k]);
				if(k) pls(g[j][k-1], (ll)f[j][k] * k%p);
			}
	}

	int ans = g[0][0];
	for(int i=1;i<=ct;++i)
		ans = (ll)ans * i%p;
	printf("%d\n", ans);
	return 0;
}