#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=605;
const int MOD=1e9+7;
int add (int x,int y)   {x=x+y;return x>=MOD?x-MOD:x;}
int mul (int x,int y)   {return (LL)x*y%MOD;}
int dec (int x,int y)   {x=x-y;return x<0?x+MOD:x;}
int Pow (int x,int y)
{
	if (y==1) return x;
	int lalal=Pow(x,y>>1);
	lalal=mul(lalal,lalal);
	if (y&1) lalal=mul(lalal,x);
	return lalal;
}
bool in[N];
int n;
int a[N];
int cnt=0;
int f[N][N][N];
int g[N],num;
bool vis[N];
int nn;
bool cmp (int x,int y)	{return x>y;}
int main()
{
	memset(in,false,sizeof(in));
	memset(vis,false,sizeof(vis));
	scanf("%d",&n);n<<=1;nn=n;
	for (int u=1;u<=n;u++)	scanf("%d",&a[u]);
	int cnt=0;
	for (int u=1;u<=n;u+=2)
	{
		if (a[u]==-1&&a[u+1]==-1) cnt++;
		if (a[u]>0&&a[u+1]>0) vis[a[u]]=true,vis[a[u+1]]=true;
		if (a[u]>0) in[a[u]]=true;
		if (a[u+1]>0) in[a[u+1]]=true;
	}
	for (int u=n;u>=1;u--) if (!vis[u]) g[++num]=u;
//	for (int u=1;u<=num;u++) printf("%d ",g[u]);printf("\n");
	f[0][0][0]=1;
	for (int u=1;u<=num;u++)
	for (int i=0;i<=min(nn,num);i++)
	for (int j=0;j<=min(nn,num);j++)
	if (f[u-1][i][j])
	{
		//printf("%d %d %d %d\n",u,i,j,f[u-1][i][j]);
		if (in[g[u]])//如果在集合里面 
		{
			f[u][i][j+1]=add(f[u][i][j+1],f[u-1][i][j]);
			if (i) f[u][i-1][j]=add(f[u][i-1][j],f[u-1][i][j]);
		}
		else
		{
			f[u][i+1][j]=add(f[u][i+1][j],f[u-1][i][j]);
			if (i) f[u][i-1][j]=add(f[u][i-1][j],f[u-1][i][j]);
			if (j) f[u][i][j-1]=add(f[u][i][j-1],mul(f[u-1][i][j],j));
		}
	}
	int ans=f[num][0][0];
	for (int u=1;u<=cnt;u++) ans=mul(ans,u);
	printf("%d\n",ans);
	return 0;
}