#pragma region
#ifndef M207
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#endif
#include <bits/stdc++.h>
using namespace std;
#define ri register int
#define il inline
#define LL long long
#define uint unsigned int
#define ull unsigned long long
#define solid const auto &
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
#define gm int mid((l+r)/2)
#define space putchar(' ')
#define enter putchar('\n')
#define rd() ({ri t;in(t);t;})
#define Size(x) ((int)x.size())
#define mem(x,y) memset(x,y,sizeof(x))
template<class T>il void in(T &x)
{
	x=0; char c=getchar(); bool f=0;
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=x*10+(c^'0'),c=getchar();
	f?x=-x:0;
}
template<class T>il void out(T x,const char c='\n')
{
	static short st[40]; short m=0;
	if(x<0) putchar('-'),x=-x;
	do st[++m]=x%10,x/=10; while(x);
	while(m) putchar(st[m--]|'0');
	putchar(c);
}
template<class T>il void err(const T &x,const char c='\n') {cerr<<x<<c;}
template<class T,class ...Args>il void in(T &x,Args &...args) {in(x); in(args...);}
template<class T,class ...Args>il void out(const T &x,const Args &...args) {out(x,' '); out(args...);}
template<class T,class ...Args>il void err(const T &x,const Args &...args) {err(x,' '); err(args...);}
template<class T>il void prt(T a[],int n) {for(ri i=0; i<n; ++i) out(a[i],i==n-1?'\n':' ');}
template<class T>il void clr(T a[],int n) {memset(a,0,sizeof(T)*n);}
template<class T>il void clr(T *a,T *b) {memset(a,0,sizeof(T)*(b-a));}
template<class T>il bool ckmax(T &a,const T &b) {return a<b?a=b,1:0;}
template<class T>il bool ckmin(T &a,const T &b) {return a>b?a=b,1:0;}
namespace MOD_CALC
{
const int md=1e9+7,inv2=(md+1)/2;
il int add(const int a,const int b) {return a+b>=md?a+b-md:a+b;}
il int sub(const int a,const int b) {return a-b<0?a-b+md:a-b;}
il int mul(const int a,const int b) {return (LL)a*b%md;}
il void inc(int &a,const int b) {(a+=b)>=md?a-=md:0;}
il void dec(int &a,const int b) {(a-=b)<0?a+=md:0;}
il int qpow(int a,int b) {int r=1; for(; b; b>>=1,a=mul(a,a)) if(b&1) r=mul(r,a); return r;}
il int qpow(int a,int b,const int p) {int r=1; for(; b; b>>=1,a=(LL)a*a%p) if(b&1) r=(LL)r*a%p; return r;}
il int mdinv(const int a) {return qpow(a,md-2);}
template<class ...Args>il int add(const int a,const int b,const Args &...args) {return add(add(a,b),args...);}
template<class ...Args>il int mul(const int a,const int b,const Args &...args) {return mul(mul(a,b),args...);}
} using namespace MOD_CALC;
namespace i207M
{
#pragma endregion
#define N 605
int n;
int a[N];
int zt[N];
int _dp[2][N][N];
signed main()
{
#ifdef M207
	freopen("in.in","r",stdin);
	// freopen("ot.out","w",stdout);
#endif
	in(n);
	for(ri i=1; i<=2*n; ++i) in(a[i]);
	int cnt0=0,cnt1=0;
	for(ri i=1; i<=2*n; i+=2)
	{
		int t=(a[i]!=-1)+(a[i+1]!=-1);
		if(t==2) zt[a[i]]=zt[a[i+1]]=2;
		else if(t==1) zt[max(a[i],a[i+1])]=1,++cnt1;
		else ++cnt0;
	}
	auto f=_dp[0],g=_dp[1];
	f[0][0]=1;
	for(ri i=2*n; i>=1; --i)
	{
		if(zt[i]==2) continue;
		swap(f,g); memset(f,0,sizeof _dp[0]);
		for(ri j=0; j<=i; ++j)
			for(ri k=0; k<=i&&k<=cnt1; ++k)
			{
				int v=g[j][k];
				if(!v) continue;
				if(zt[i]==1)
				{
					if(j) inc(f[j-1][k],v);
					inc(f[j][k+1],v);
				}
				else
				{
					inc(f[j+1][k],v);
					if(j) inc(f[j-1][k],v);
					if(k) inc(f[j][k-1],mul(v,k));
				}
			}
	}
	int ans=f[0][0];
	for(ri i=1; i<=cnt0; ++i) ans=mul(ans,i);
	out(ans);
	return 0;
}
#pragma region
}
signed main()
{
	i207M::main();
	return 0;
}
#pragma endregion


Measured memory_bytes: 3072