#include<bits/stdc++.h>
#define llong long long
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int N = 300;
const int P = 1e9+7;
llong f[N+N+3][N+3][N+3];
int a[N+N+3];
bool used[N+N+3];
vector<int> vec;
int n;

llong updsum(llong &x,llong y) {x = x+y>=P?x+y-P:x+y;}

int main()
{
	scanf("%d",&n); int cnt1 = 0,cnt2 = 0;
	for(int i=1; i<=n; i++)
	{
		scanf("%d%d",&a[i+i-1],&a[i+i]);
		if(a[i+i-1]!=-1&&a[i+i]!=-1)
		{
			vec.push_back(a[i+i-1]),vec.push_back(a[i+i]);
			i--,n--;
		}
		else if(a[i+i-1]==-1&&a[i+i]==-1) {cnt1++;}
		else {cnt2++;}
	}
	sort(vec.begin(),vec.end());
	for(int i=1; i<=n+n; i++) {a[i] -= (lower_bound(vec.begin(),vec.end(),a[i])-vec.begin());}
//	printf("a: "); for(int i=1; i<=n+n; i++) printf("%d ",a[i]); puts("");
	for(int i=1; i<=n+n; i++) if(a[i]!=-1) {used[a[i]] = true;}
	f[n+n+1][0][0] = 1ll;
	for(int i=n+n+1; i>=2; i--)
	{
		for(int j=0; j<=cnt1+cnt2; j++)
		{
			for(int k=0; k<=cnt2; k++)
			{
				llong x = f[i][j][k]; if(!x) continue;
				if(!used[i-1])
				{
					updsum(f[i-1][j+1][k],x);
					if(j>0) {updsum(f[i-1][j-1][k],x);}
					updsum(f[i-1][j][k-1],x*k%P);
				}
				else
				{
					updsum(f[i-1][j][k+1],x);
					if(j>0) {updsum(f[i-1][j-1][k],x);}
				}
			}
		}
	}
	llong ans = f[1][0][0]; int tmp = 0;
	for(int i=1; i<=n; i++) tmp += (a[i+i-1]==-1)&&(a[i+i]==-1);
	while(tmp) {ans = ans*tmp%P; tmp--;}
	printf("%lld\n",ans);
	return 0;
}