#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll dp[606][303][303];
int main()
{
	int n;
	cin>>n;
	int a[606];
	for(int i=0; i<2*n; i++){
		cin>>a[i];
	}
	int b[606], c[606]={};
	fill(b+1, b+2*n+1, 1);
	int m=0;
	for(int i=0; i<n; i++){
		if(a[2*i]>=0 && a[2*i+1]>=0){
			b[a[2*i]]=b[a[2*i+1]]=0;
		}
	}
	for(int i=1; i<=2*n; i++){
		if(b[i]>0){
			m++;
			b[i]=m;
		}
	}
	if(m==0){
		cout<<1<<endl;
		return 0;
	}
	int cnt=0;
	for(int i=0; i<n; i++){
		if(a[2*i]>=0 && a[2*i+1]>=0) continue;
		if(a[2*i]>=0) c[b[a[2*i]]]=1, cnt++;
		if(a[2*i+1]>=0) c[b[a[2*i+1]]]=1, cnt++;
	}
	dp[m+1][0][0]=1;
	for(int i=m+1; i>=2; i--){
		for(int j=0; j<=min(m/2, m+1-i); j++){
			for(int l=0; l<=min(m/2, m+1-i-j); l++){
				if(c[i-1]){
					(dp[i-1][j][l+1]+=dp[i][j][l])%=MOD;
					if(j) (dp[i-1][j-1][l]+=dp[i][j][l])%=MOD;
				}else{
					dp[i-1][j+1][l]+=dp[i][j][l];
					if(l) (dp[i-1][j][l-1]+=l*dp[i][j][l])%=MOD;
					if(j) (dp[i-1][j-1][l]+=dp[i][j][l])%=MOD;
				}
			}
		}
	}
	ll ans=dp[1][0][0];
	for(int i=1; i<=m/2-cnt; i++) (ans*=i)%=MOD;
	cout<<ans<<endl;
	return 0;
}