//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n, m, a[611];
void upd(int &x, int v) {x=x+v>=mod?x+v-mod:x+v;}
int n1, n2;
int dp[2][311][311];
int pos[611];
ll fac[611], ifac[611], inv[611];
int main()
{
	fac[0] = 1;
	for (int i=1; i<=600; i++) fac[i] = fac[i-1]*i%mod;
	inv[1] = 1;
	for (int i=2; i<=600; i++) inv[i] = mod-1ll*inv[mod%i]*(mod/i)%mod;
	ifac[0] = 1;
	for (int i=1; i<=600; i++) ifac[i] = ifac[i-1]*inv[i]%mod;
	geti(n);
	for (int i=1; i<=n; i++)
	{
		int x, y;
		getii(x, y);
		int cnt = (x==-1)+(y==-1);
		if (cnt==1) n1++;
		if (cnt==2) n2++;
		if (cnt==0) pos[x] = pos[y] = -1;
		else
		{
			if (x!=-1) pos[x] = i*2-1;
			if (y!=-1) pos[y] = i*2;
		}
	}
	int p = 0, c = 0, c1lft = n1;
	dp[p][n1][n2] = 1;
	for (int i=1; i<=n+n; i++)
	{
		int np = p^1;
		memset(dp[np], 0, sizeof(dp[np]));
		if (!pos[i])
		{
			for (int c1=0; c1<=n; c1++)
			{
				for (int c2=0; c2<=n; c2++)
				{
					int &cur = dp[p][c1][c2];
					if (!cur) continue;
					int uc1 = (n2-c2)+(n1-c1)-(c-(n2-c2));
					if (c2>0) upd(dp[np][c1][c2-1], 1ll*cur*c2%mod);
					if (c1>0) upd(dp[np][c1-1][c2], 1ll*cur*c1%mod);
					if (uc1>0) upd(dp[np][c1][c2], cur);
				}
			}
			c++;
		}
		else
		{
			if (pos[i]==-1)
			{
				np = p;
				continue;
			}
			for (int c1=0; c1<=n; c1++)
			{
				for (int c2=0; c2<=n; c2++)
				{
					int &cur = dp[p][c1][c2];
					if (!cur) continue;
					int uc1 = (n2-c2)+(n1-c1-(c-(n2-c2)));
					assert(c1<=c1lft);
					ll prob = 1ll*c1*inv[c1lft]%mod;
					if (c1>0) upd(dp[np][c1-1][c2], 1ll*cur*prob%mod);
					ll iprob = (1-prob+mod)%mod;
					upd(dp[np][c1][c2], 1ll*cur*iprob%mod);
				}
			}
			c1lft--;
		}
		p = np;
	}
	cout<<dp[p][0][0]<<endl;
	return 0;
}


Measured memory_bytes: 1024