using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cassert>
#define N 310
#define mo 1000000007
#define ll long long
int n;
int bz[N*2];
int f[N*2][N][N];
inline void add(int &a,ll b){a=(a+b)%mo;}
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	scanf("%d",&n);
	for (int i=n;i>=1;--i){
		int x,y;
		scanf("%d%d",&x,&y);
		if (x!=-1 && y!=-1)
			bz[x]=-1,bz[y]=-1;
		else if (x!=-1)
			bz[x]=1;
		else if (y!=-1)
			bz[y]=1;
	}
	int tmpn=n;
	n=0;
	for (int i=1;i<=tmpn*2;++i)
		if (bz[i]!=-1)
			bz[++n]=bz[i];
	n>>=1;
	f[2*n+1][0][0]=1;
	for (int i=2*n+1;i>1;--i)
		for (int j=0;j<=2*n-i+1 && j<=n;++j)
			for (int k=0;j+k<=2*n-i+1 && k<=n;++k){
				ll tmp=f[i][j][k];
				if (!tmp)
					continue;
				if (bz[i-1]==1){
					add(f[i-1][j][k+1],tmp);
					if (j)
						add(f[i-1][j-1][k],tmp);
				}
				else{
					add(f[i-1][j+1][k],tmp);
					if (j)
						add(f[i-1][j-1][k],tmp);
					if (k)
						add(f[i-1][j][k-1],tmp*k);
				}
			}
	int cnt=0;
	ll ans=1;
	for (int i=1;i<=2*n;++i) 
		if (bz[i]==1)
			cnt++;
	for (int i=1;i<=n-cnt;++i)
		ans=ans*i%mo;
	ans=ans*f[1][0][0]%mo;
	printf("%lld\n",ans);
	return 0;
}