#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
const int N=601,mod=1e9+7;
typedef long long ll;
template<class T>inline void Inc(T&x,int y){x+=y;if(x>=mod) x-=mod;}
int vis[N];
int a[N];
int dp[2][N][N];
int n;

int main()
{
	init(n);n<<=1;int n1=0,n2=0;
	for(int i=1;i<=n;++i) init(a[i]);
	for(int i=1;i<=n;i+=2){
		if(~a[i]&&~a[i+1]) vis[a[i]]=vis[a[i+1]]=2;
		else if(a[i]!=-1) vis[a[i]]=1,++n1;
		else if(a[i+1]!=-1) vis[a[i+1]]=1,++n1;
		else ++n2;
	}
	int cur=0;int half=n>>1;
	dp[0][0][0]=1;
	for(int i=n;i;--i) {
		if(vis[i]==2) continue;
		cur^=1;Set(dp[cur],0);
		for(int j=0;j<=half;++j){
			for(int k=0;k<=half;++k) {
				if(!dp[cur^1][j][k]) continue;
				int f=dp[cur^1][j][k];
				if(vis[i]==1) {
					if(k) Inc(dp[cur][j][k-1],f);
					Inc(dp[cur][j+1][k],f);
				}
				else {
					Inc(dp[cur][j][k+1],f);
					if(k) Inc(dp[cur][j][k-1],f);
					if(j) Inc(dp[cur][j-1][k],(ll)f*j%mod);
				}
			}
		}
	}
	int fac=1;
	while(n2) fac=(ll)fac*n2%mod,--n2;
	printf("%lld\n",(ll)dp[cur][0][0]*fac%mod);
}
