import sys
import itertools

input = sys.stdin.readline

n = int(input())
a_s = [0] * n
xss = []
yss = []
for i in range(n):
	a_s[i] = int(input())
	xss.append([])
	yss.append([])
	for _ in range(a_s[i]):
		x, y = map(int, input().split())
		xss[i].append(x)
		yss[i].append(y)

# print(xss)
# print(yss)

tmp_shojiki = [True] * n
for i in range(n):
	for shojiki in set(itertools.permutations(tmp_shojiki)):
		# print(i, shojiki)
		all_shojiki = True
		for j in range(n):
			if not shojiki[j]:
				continue
			for k in range(a_s[i]):
				x, y = xss[j][k] - 1, yss[j][k]
				if y == 1:
					if shojiki[x] == False:
						all_shojiki = False
				else:
					if shojiki[x] == True:
						all_shojiki = False
		if all_shojiki:
			print(n - i)
			sys.exit()

	tmp_shojiki[i] = False

print(0)