#include<algorithm>
#include<cstring>
#include<cstdio>
#define LL long long
#define Re register int
using namespace std;
const int N=303,P=1e9+7;
int n,m,cnt1,cnt2,ok[N<<1],vis[N<<1],A[N<<1],B[N<<1],dp[N<<1][N][N];
inline void in(Re &x){
    int f=0;x=0;char c=getchar();
    while(c<'0'||c>'9')f|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
    x=f?-x:x;
}
int main(){
//	freopen("123.txt","r",stdin);
	in(n);
	for(Re i=1;i<=(n<<1);++i)in(A[i]);
	for(Re i=1;i<=(n<<1);i+=2)
		if(A[i]==-1&&A[i+1]==-1)++cnt1;
		else if(A[i]>0&&A[i+1]>0)vis[A[i]]=vis[A[i+1]]=1;
		else ++cnt2,ok[A[i]>0?A[i]:A[i+1]]=1;
	for(Re i=(n<<1);i>=1;--i)if(!vis[i])B[++m]=i;
	dp[0][0][0]=1;
	for(Re i=1;i<=m;++i)
		for(Re j=0;j<=cnt1+cnt2;++j)
			for(Re k=0;k<=cnt2;++k)if(dp[i-1][j][k]){
				if(ok[B[i]]){
					(dp[i][j][k+1]+=dp[i-1][j][k])%=P;
					if(j)(dp[i][j-1][k]+=dp[i-1][j][k])%=P;
				}
				else{
					(dp[i][j+1][k]+=dp[i-1][j][k])%=P;
					if(j)(dp[i][j-1][k]+=dp[i-1][j][k])%=P;
					if(k)(dp[i][j][k-1]+=(LL)k*dp[i-1][j][k]%P)%=P;
				}
			}
	Re ans=dp[m][0][0];
	for(Re i=1;i<=cnt1;++i)ans=(LL)ans*i%P;
	printf("%d\n",ans);
}