#include<bits/stdc++.h>
 
using namespace std;
 
#define N 800
#define LL long long
 
const LL mod=1000000007;
LL n,m,a[N],b[N],f[N][N],g[N][N];
 
void upd(LL &x,LL y){x=(x+y%mod+mod)%mod;}
 
int main(){
	scanf("%lld",&n);
	for (LL i=0;i<n*2;++i) scanf("%lld",a+i);
	for (LL i=0;i<n;++i){
		LL x=a[i<<1],y=a[i<<1|1];
		if (x>0&&y>0){b[x]=b[y]=-1; continue;}
		if (x<0&&y<0){++m; continue;}
		if (x>0) b[x]=1;
		if (y>0) b[y]=1;
	}
	f[0][0]=1;
	for (LL i=1,x=0,y=0;i<=n*2;++i){
		if (b[i]<0) continue;
		memset(g,0,sizeof g);
		if (b[i]>0){
			for (LL j=0;j<=x+y;++j)
				for (LL k=0;k<=x+y;++k){
					upd(g[j+1][k],f[j][k]);//m
					if (k) upd(g[j][k-1],f[j][k]*k);//m
				}
			++x;
		}
		else{
			for (LL j=0;j<=x+y;++j)
				for (LL k=0;k<=y;++k){
					if ((j-k-x+y)>=0) upd(g[j+1][k],f[j][k]);//m-1
					if (j) upd(g[j-1][k],f[j][k]);//m
					upd(g[j][k+1],f[j][k]);//m
				}
			++y;
		}
		memcpy(f,g,sizeof f);
	}
	for (int i=1;i<=m;i++) f[0][0]=1LL*f[0][0]*i%mod;
	printf("%lld\n",f[0][0]);
	
	return 0;
}