#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	char ch; bool flag = false; res = 0; 
	while (ch = getchar(), !isdigit(ch) && ch != '-');
	ch == '-' ? flag = true : res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
	flag ? res = -res : 0;
}

const int N = 305;
const int M = 605;
const int mod = 1e9 + 7;
int s1[M], s2[M], a[M], b[M], f[2][N][M];
bool tag[M], del[M]; 
int n, m, cnt;

inline void add(int &x, int y)
{
	x += y;
	x >= mod ? x -= mod : 0;
}

inline void Delete(int x)
{
	del[x] = true;
	for (int i = 1; i <= m; ++i)
		if (!del[i] && a[i] > a[x])
			--a[i];
}

int main()
{	
	read(n);
	m = n << 1;
	for (int i = 1; i <= m; ++i)
		read(a[i]);
	for (int i = 1; i <= m; i += 2)
		if (~a[i] && ~a[i + 1])
		{
			Delete(i);
			Delete(i + 1);
		}
	n = 0; 
	for (int i = 1; i <= m; i += 2)
		if (!del[i])
		{
			if (~a[i])
				tag[a[i]] = true;
			if (~a[i + 1])
				tag[a[i + 1]] = true;
			if (a[i] == -1 && a[i + 1] == -1)
				++cnt;
			++n;
		}
	m = n << 1;
	f[m + 1 & 1][0][0] = 1;
	for (int i = m; i >= 1; --i)
	{
		int now = i & 1, lst = now ^ 1;
		s1[i] = s1[i + 1] + tag[i];
		s2[i] = s2[i + 1] + !tag[i];
		if (tag[i])
		{
			for (int j = 0; j <= s1[i]; ++j)
				for (int k = 0; k <= s2[i]; ++k)
				{
					f[now][j][k] = j > 0 ? f[lst][j - 1][k] : 0;
					add(f[now][j][k], f[lst][j][k + 1]);
				}	
		}
		else
		{
			for (int j = 0; j <= s1[i]; ++j)
				for (int k = 0; k <= s2[i]; ++k)
					f[now][j][k] = (1ll * f[lst][j + 1][k] * (j + 1) 
				                  + (k > 0 ? f[lst][j][k - 1] : 0) + f[lst][j][k + 1]) % mod; 
		}
	}
	int res = f[1][0][0];
	for (int i = 1; i <= cnt; ++i)
		res = 1ll * res * i % mod;
	printf("%d\n", res);
	return 0;
}