#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
#include <map>
 
using namespace std;

typedef long long ll;

const int MAXN = 305;
const ll MOD = 1000000007;

int n,ans;
int tp[MAXN << 1];
int match[MAXN << 1];
int f[MAXN << 1][MAXN][MAXN];

bool vis[MAXN << 1];

vector<int> v;

int main()
{
	scanf("%d",&n);
	int N = n,cnt = 0;
	for (int a,b,i = 1;i <= n;i++)
	{
		scanf("%d%d",&a,&b);
		if (~a && ~b)
		{
			vis[a] = vis[b] = 1;
			N--;
		}
		else if (a == -1 && b == -1)
			cnt++;
		else if (~a)
			v.push_back(a);
		else if (~b)
			v.push_back(b);
	}
	for (int i = 1;i <= 2 * n;i++)
		match[i] = match[i - 1] + !vis[i];
	for (int i = 0;i < v.size();i++)
		tp[match[v[i]]] = 1;
	f[2 * N + 1][0][0] = 1;
	for (int i = 2 * N + 1;i > 1;i--)
		for (int j = 0;j <= N;j++)
			for (int k = 0;k <= N;k++)
				if (f[i][j][k])
				{
					if (tp[i - 1])
					{
						(f[i - 1][j + 1][k] += f[i][j][k]) %= MOD;
						if (k)
							(f[i - 1][j][k - 1] += f[i][j][k]) %= MOD;
					}
					else
					{
						(f[i - 1][j][k + 1] += f[i][j][k]) %= MOD;
						if (j)
							(f[i - 1][j - 1][k] += (ll)f[i][j][k] * j % MOD) %= MOD;
						if (k)
							(f[i - 1][j][k - 1] += f[i][j][k]) %= MOD;
					}
				}
	int ans = f[1][0][0];
	while (cnt)
		ans = (ll)ans * (cnt--) % MOD;
	printf("%d\n",ans);
	return 0;
}