import itertools

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



n = int(readline())

xy = []

for _ in range(n):

    m = int(readline())

    tmp = [list(map(int, readline().split())) for _ in range(m)]

    xy.append(tmp)



ans = 0



for l in list(itertools.product([0, 1], repeat=n)):

    bl = True

    for i,a in enumerate(l):

        if a == 1:

            for b in xy[i]:

                if l[b[0] - 1] != b[1]:

                    bl = False

    if bl:

        ans = max(ans, sum(l))

print(ans)
import itertools

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



n = int(readline())

xy = []

for _ in range(n):

    m = int(readline())

    tmp = [list(map(int, readline().split())) for _ in range(m)]

    xy.append(tmp)

    

# 逆から

for l in sorted(itertools.product([0, 1], repeat=n),reverse=True):

    bl = True

    for i, a in enumerate(l):

        if a == 1:

            for b in xy[i]:

                if l[b[0] - 1] != b[1]:

                    bl = False

                    break

    if bl:

        print((sum(l)))

        exit()

print('0')
import itertools
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
xy = []
for _ in range(n):
    m = int(readline())
    tmp = [list(map(int, readline().split())) for _ in range(m)]
    xy.append(tmp)
ans = 0
for l in list(itertools.product([0, 1], repeat=n)):
    bl = True
    for i, a in enumerate(l):
        if a == 1:
            for b in xy[i]:
                if l[b[0] - 1] != b[1]:
                    bl = False
    if bl:
        ans = max(ans, sum(l))
print(ans)

import itertools
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
xy = []
for _ in range(n):
    m = int(readline())
    tmp = [list(map(int, readline().split())) for _ in range(m)]
    xy.append(tmp)
# 逆から
for l in sorted(itertools.product([0, 1], repeat=n), reverse=True):
    bl = True
    for i, a in enumerate(l):
        if a == 1:
            for b in xy[i]:
                if l[b[0] - 1] != b[1]:
                    bl = False
                    break
    if bl:
        print((sum(l)))
        exit()
print("0")

-ans = 0 -for l in list(itertools.product([0, 1], repeat=n)): +# 逆から +for l in sorted(itertools.product([0, 1], repeat=n), reverse=True): +                    break -        ans = max(ans, sum(l)) -print(ans) +        print((sum(l))) +        exit() +print("0")