import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log

from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left, insort, insort_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

from decimal import Decimal

def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10**9 + 7

from decimal import *



N = INT()

xy = []



for i in range(N):

	A = INT()

	xy.append([LIST() for _ in range(A)])



ans = 0

for i in range(1<<N):

	i = list("{:b}".format(i).zfill(N))

	for j in range(N):

		if i[j] == "1":

			for x, y in xy[j]:

				if y != int(i[x-1]):

					break

			else:

				continue

			break

	else:

		tmp = sum([int(x) for x in i])

		ans = max(ans, tmp)

print(ans)

import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log

from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left, insort, insort_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

from decimal import Decimal

def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10**9 + 7

from decimal import *



N = INT()

xy = []



for i in range(N):

	A = INT()

	xy.append([LIST() for _ in range(A)])



ans = 0

for X in product((0, 1), repeat=N):

	for j in range(N):

		if X[j] == 1:

			for x, y in xy[j]:

				if X[x-1] != y:

					break

			else:

				continue

			break

	else:

		ans = max(ans, sum(X))



print(ans)
import sys, re
from collections import deque, defaultdict, Counter
from math import (
    ceil,
    sqrt,
    hypot,
    factorial,
    pi,
    sin,
    cos,
    tan,
    asin,
    acos,
    atan,
    radians,
    degrees,
)  # , log2, log
from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    product,
    groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(map(int, input().split()))


def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))


sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
from decimal import *

N = INT()
xy = []
for i in range(N):
    A = INT()
    xy.append([LIST() for _ in range(A)])
ans = 0
for i in range(1 << N):
    i = list("{:b}".format(i).zfill(N))
    for j in range(N):
        if i[j] == "1":
            for x, y in xy[j]:
                if y != int(i[x - 1]):
                    break
            else:
                continue
            break
    else:
        tmp = sum([int(x) for x in i])
        ans = max(ans, tmp)
print(ans)

import sys, re
from collections import deque, defaultdict, Counter
from math import (
    ceil,
    sqrt,
    hypot,
    factorial,
    pi,
    sin,
    cos,
    tan,
    asin,
    acos,
    atan,
    radians,
    degrees,
)  # , log2, log
from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    product,
    groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(map(int, input().split()))


def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))


sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
from decimal import *

N = INT()
xy = []
for i in range(N):
    A = INT()
    xy.append([LIST() for _ in range(A)])
ans = 0
for X in product((0, 1), repeat=N):
    for j in range(N):
        if X[j] == 1:
            for x, y in xy[j]:
                if X[x - 1] != y:
                    break
            else:
                continue
            break
    else:
        ans = max(ans, sum(X))
print(ans)

-for i in range(1 << N): -    i = list("{:b}".format(i).zfill(N)) +for X in product((0, 1), repeat=N): -        if i[j] == "1": +        if X[j] == 1: -                if y != int(i[x - 1]): +                if X[x - 1] != y: -        tmp = sum([int(x) for x in i]) -        ans = max(ans, tmp) +        ans = max(ans, sum(X))