n = int(eval(input()))



evi_all = []

for _ in range(n):

    evi = []

    for _ in range(int(eval(input()))):

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

        evi.append((x - 1, y))

    evi_all.append(evi)



ans = 0

for mask in range(2 ** n):

    flg = True

    for bit in range(n):

        if (mask >> bit) & 1:

            for x, y in evi_all[bit]:

                if (y == 1 and (mask >> x & 1) == 0) or (y == 0 and (mask >> x & 1) == 1):

                    flg = False



    if flg:

        cnt = 0

        for bit_2 in range(n):

            if (mask >> bit_2) & 1:

                cnt += 1

        ans = max(ans, cnt)



print(ans)

import sys

from itertools import product



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

    n = int(eval(input()))

    query = [[] for _ in range(n)]

    for i in range(n):

        a = int(eval(input()))

        for _ in range(a):

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

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



    res = 0

    for pattern in product([0, 1], repeat=n):

        for idx, p in enumerate(pattern):

            if p == 1:

                for x, y in query[idx]:

                    if pattern[x] != y:

                        break

                else:

                    continue

                break

        else:

            res = max(res, sum(pattern))



    print(res)





if __name__ == '__main__':

    resolve()

n = int(eval(input()))
evi_all = []
for _ in range(n):
    evi = []
    for _ in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        evi.append((x - 1, y))
    evi_all.append(evi)
ans = 0
for mask in range(2**n):
    flg = True
    for bit in range(n):
        if (mask >> bit) & 1:
            for x, y in evi_all[bit]:
                if (y == 1 and (mask >> x & 1) == 0) or (
                    y == 0 and (mask >> x & 1) == 1
                ):
                    flg = False
    if flg:
        cnt = 0
        for bit_2 in range(n):
            if (mask >> bit_2) & 1:
                cnt += 1
        ans = max(ans, cnt)
print(ans)

import sys
from itertools import product

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n = int(eval(input()))
    query = [[] for _ in range(n)]
    for i in range(n):
        a = int(eval(input()))
        for _ in range(a):
            x, y = list(map(int, input().split()))
            query[i].append([x - 1, y])
    res = 0
    for pattern in product([0, 1], repeat=n):
        for idx, p in enumerate(pattern):
            if p == 1:
                for x, y in query[idx]:
                    if pattern[x] != y:
                        break
                else:
                    continue
                break
        else:
            res = max(res, sum(pattern))
    print(res)


if __name__ == "__main__":
    resolve()

-n = int(eval(input())) -evi_all = [] -for _ in range(n): -    evi = [] -    for _ in range(int(eval(input()))): -        x, y = list(map(int, input().split())) -        evi.append((x - 1, y)) -    evi_all.append(evi) -ans = 0 -for mask in range(2**n): -    flg = True -    for bit in range(n): -        if (mask >> bit) & 1: -            for x, y in evi_all[bit]: -                if (y == 1 and (mask >> x & 1) == 0) or ( -                    y == 0 and (mask >> x & 1) == 1 -                ): -                    flg = False -    if flg: -        cnt = 0 -        for bit_2 in range(n): -            if (mask >> bit_2) & 1: -                cnt += 1 -        ans = max(ans, cnt) -print(ans) +import sys +from itertools import product + +sys.setrecursionlimit(10**7) +f_inf = float("inf") +mod = 10**9 + 7 + + +def resolve(): +    n = int(eval(input())) +    query = [[] for _ in range(n)] +    for i in range(n): +        a = int(eval(input())) +        for _ in range(a): +            x, y = list(map(int, input().split())) +            query[i].append([x - 1, y]) +    res = 0 +    for pattern in product([0, 1], repeat=n): +        for idx, p in enumerate(pattern): +            if p == 1: +                for x, y in query[idx]: +                    if pattern[x] != y: +                        break +                else: +                    continue +                break +        else: +            res = max(res, sum(pattern)) +    print(res) + + +if __name__ == "__main__": +    resolve()