/*
Time never waits.
It delivers all equally to the same end.
You, who wish to safeguard the future, however limited it may be...
You will be given one year;
go forth without falter, with your heart as your guide...
*/

#include<bits/stdc++.h>
using namespace std;
#define RI register int
const int mod=1e9+7;
int n,cnt,js,ans;
int a[605],b[605],vis[605],f[605][305][305];

int qm(int x) {return x>=mod?x-mod:x;}
void DP() {
	f[0][0][0]=1;
	for(RI i=1;i<=js;++i) {
		for(RI j=0;j<=n;++j)
			for(RI k=0;k<=n;++k) {
				if(!f[i-1][j][k]) continue;
				if(vis[b[i]]) {
					f[i][j][k+1]=qm(f[i][j][k+1]+f[i-1][j][k]);
					if(j) f[i][j-1][k]=qm(f[i][j-1][k]+f[i-1][j][k]);
				}
				else {
					f[i][j+1][k]=qm(f[i][j+1][k]+f[i-1][j][k]);
					if(j) f[i][j-1][k]=qm(f[i][j-1][k]+f[i-1][j][k]);
					if(k) f[i][j][k-1]=qm(f[i][j][k-1]+1LL*k*f[i-1][j][k]%mod);
				}
			}
	}
}
int main()
{
	scanf("%d",&n);
	for(RI i=1;i<=n+n;++i) scanf("%d",&a[i]);
	for(RI i=1;i<=n+n;i+=2) {
		if(a[i]==-1&&a[i+1]==-1) ++cnt;
		else if(a[i]==-1) vis[a[i+1]]=1;
		else if(a[i+1]==-1) vis[a[i]]=1;
		else vis[a[i+1]]=vis[a[i]]=2;
	}
	for(RI i=n+n;i>=1;--i) if(vis[i]!=2) b[++js]=i;
	DP(),ans=f[js][0][0];
	for(RI i=1;i<=cnt;++i) ans=1LL*ans*i%mod;
	printf("%d\n",ans);
	return 0;
}