#include <bits/stdc++.h>

using namespace std;

int n, a[20], x[20][20], y[20][20], f[20], ans = 0;

void dfs(int x, int ho)
{
	if (x > n)
	{
		for (int i = 1; i <= n; i++)
			if (f[i])
				for (int j = 1; j <= a[i]; j++)
					if (f[::x[i][j]] != y[i][j])
						return;
		ans = max(ans, ho);
		return;
	}
	f[x] = 0;
	dfs(x + 1, ho);
	f[x] = 1;
	dfs(x + 1, ho + 1);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		for (int j = 1; j <= a[i]; j++)
			cin >> x[i][j] >> y[i][j];
	}
	dfs(1, 0);
	cout << ans << endl;

	return 0;
}