#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=605,Mod=1e9+7;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,cnt,opt[MAXN],F[2][MAXN][MAXN];
inline void Add(int&x,int y){x+=y,x>=Mod?x-=Mod:0;}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();Rep(i,1,n){
		int x=read(),y=read();
		if(!(~x)||!(~y))(~x?opt[x]=1:0),(~y?opt[y]=1:0),(!(~x)&&!(~y)?cnt++:0);
		else opt[x]=opt[y]=-1;
	}int now=0,s1=0,s2=0;F[0][0][0]=1;
	Red(i,2*n,1)if(~opt[i]){
		now^=1,memset(F[now],0,sizeof(F[now]));		
		Rep(j,0,min(s1,n))Rep(k,0,min(s2,n))if(F[now^1][j][k]){
			if(opt[i]){
				if(j<n)Add(F[now][j+1][k],F[now^1][j][k]);
				if(k)Add(F[now][j][k-1],F[now^1][j][k]);
			}else{
				if(k<n)Add(F[now][j][k+1],F[now^1][j][k]);
				if(j)Add(F[now][j-1][k],1ll*F[now^1][j][k]*j%Mod);
				if(k)Add(F[now][j][k-1],1ll*F[now^1][j][k]*(cnt-(s2-s1+j-k>>1)+Mod)%Mod);
			}
		}if(opt[i])s1++;else s2++;
	}cout<<F[now][0][0]<<'\n';
	return 0;
}


