import itertools

import numpy as np



N = int(eval(input()))

stl = []

for i in range(N):

    a = int(eval(input()))

    for _ in range(a):

        x, y = list(map(int, input().split()))

        stl.append((i, x-1, y))

dl = np.array(list(itertools.product([0, 1], repeat=N)), np.bool)

for i, x, y in stl:

    bl = (dl[:, i] == False) | (dl[:, x] == bool(y))

    dl = dl[bl]

res = dl.sum(axis=1).max()

print(res)

import sys

import itertools

import collections





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    n = int(readline())

    xy = []

    for i in range(n):

        a = int(readline())

        for j in range(a):

            x, y = list(map(int, readline().split()))

            xy.append([i, x-1, y])

    ls = collections.deque([v for v in itertools.product([True, False], repeat=n)])

    for i, x, y in xy:

        for j in range(len(ls)):

            lsv = ls.pop()

            if not lsv[i] or lsv[x] == bool(y):

                ls.appendleft(lsv)

    t = 0

    for i in range(len(ls)):

        t = max(t, ls[i].count(True))

    print(t)





if __name__ == '__main__':

    solve()

import itertools
import numpy as np

N = int(eval(input()))
stl = []
for i in range(N):
    a = int(eval(input()))
    for _ in range(a):
        x, y = list(map(int, input().split()))
        stl.append((i, x - 1, y))
dl = np.array(list(itertools.product([0, 1], repeat=N)), np.bool)
for i, x, y in stl:
    bl = (dl[:, i] == False) | (dl[:, x] == bool(y))
    dl = dl[bl]
res = dl.sum(axis=1).max()
print(res)

import sys
import itertools
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n = int(readline())
    xy = []
    for i in range(n):
        a = int(readline())
        for j in range(a):
            x, y = list(map(int, readline().split()))
            xy.append([i, x - 1, y])
    ls = collections.deque([v for v in itertools.product([True, False], repeat=n)])
    for i, x, y in xy:
        for j in range(len(ls)):
            lsv = ls.pop()
            if not lsv[i] or lsv[x] == bool(y):
                ls.appendleft(lsv)
    t = 0
    for i in range(len(ls)):
        t = max(t, ls[i].count(True))
    print(t)


if __name__ == "__main__":
    solve()

+import sys -import numpy as np +import collections -N = int(eval(input())) -stl = [] -for i in range(N): -    a = int(eval(input())) -    for _ in range(a): -        x, y = list(map(int, input().split())) -        stl.append((i, x - 1, y)) -dl = np.array(list(itertools.product([0, 1], repeat=N)), np.bool) -for i, x, y in stl: -    bl = (dl[:, i] == False) | (dl[:, x] == bool(y)) -    dl = dl[bl] -res = dl.sum(axis=1).max() -print(res) + +def solve(): +    readline = sys.stdin.buffer.readline +    mod = 10**9 + 7 +    n = int(readline()) +    xy = [] +    for i in range(n): +        a = int(readline()) +        for j in range(a): +            x, y = list(map(int, readline().split())) +            xy.append([i, x - 1, y]) +    ls = collections.deque([v for v in itertools.product([True, False], repeat=n)]) +    for i, x, y in xy: +        for j in range(len(ls)): +            lsv = ls.pop() +            if not lsv[i] or lsv[x] == bool(y): +                ls.appendleft(lsv) +    t = 0 +    for i in range(len(ls)): +        t = max(t, ls[i].count(True)) +    print(t) + + +if __name__ == "__main__": +    solve()