#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll dp[655][322][322];
int stt[655];
int main()
{
	int num;
	scanf("%d", &num);
	int c0 = 0;
	for (int i = 0; i < num; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		if (za > zb)swap(za, zb);
		if (za != -2)stt[za] = stt[zb] = -1;
		else if (zb != -2)stt[zb] = 1;
		else c0++;
	}
	dp[num + num][0][0] = 1;
	for (int i = num + num; i >= 1; i--)
	{
		if (stt[i - 1] == -1)for (int j = 0; j <= num; j++)for (int k = 0; k <= num; k++)dp[i - 1][j][k] = dp[i][j][k];
		else if (stt[i - 1] == 0)
		{
			for (int j = 0; j <= num; j++)
			{
				for (int k = 0; k <= num; k++)
				{
					if (dp[i][j][k] == 0)continue;
					dp[i - 1][j + 1][k] = (dp[i - 1][j + 1][k] + dp[i][j][k]) % mod;
					if (j > 0)dp[i - 1][j - 1][k] = (dp[i - 1][j - 1][k] + dp[i][j][k]) % mod;
					if (k > 0)dp[i - 1][j][k - 1] = (dp[i - 1][j][k - 1] + dp[i][j][k] * k) % mod;
				}
			}
		}
		else
		{
			for (int j = 0; j <= num; j++)
			{
				for (int k = 0; k <= num; k++)
				{
					if (dp[i][j][k] == 0)continue;
					dp[i - 1][j][k + 1] = (dp[i - 1][j][k + 1] + dp[i][j][k]) % mod;
					if (j > 0)dp[i - 1][j - 1][k] = (dp[i - 1][j - 1][k] + dp[i][j][k]) % mod;
				}
			}
		}
	}
	ll ans = dp[0][0][0];
	for (int i = 1; i <= c0; i++)ans = ans*i%mod;
	printf("%lld\n", ans);
}
