N = int(eval(input()))

xy = [[] for i in range(N)]



for i in range(N):

    A = int(eval(input()))

    for j in range(A):

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

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



res = 0

for i in range(2 ** N):

    cnt = 0

    for j in range(N):

        ok = True

        if i >> j & 1:

            cnt += 1

            for k in range(len(xy[j])):

                if (i >> (xy[j][k][0] - 1) & 1) != xy[j][k][1]:

                    ok = False

                    break

        if ok == False:

            cnt = 0

            break

    res = max(res, cnt)

print(res)

import sys, heapq, bisect, math, fractions

from collections import deque



N = int(eval(input()))

xy = [[] for _ in range(N)]

for i in range(N):

    a = int(eval(input()))

    for _ in range(a):

        xy[i].append(tuple(map(int, input().split())))

        

def ok(i: int, j: int):

    for x, y in xy[j]:

        if y == 0 and (i >> (x - 1) & 1 == 1):

            return False

        if y == 1 and (i >> (x - 1) & 1 == 0):

            return False

    return True



res = 0

for i in range(2 ** N):

    cnt = 0

    for j in range(N):

        if i >> j & 1 == 1:

            cnt += 1

            if not ok(i, j):

                break

    else:

        res = max(res, cnt)



print(res)
N = int(eval(input()))
xy = [[] for i in range(N)]
for i in range(N):
    A = int(eval(input()))
    for j in range(A):
        x, y = list(map(int, input().split()))
        xy[i].append([x, y])
res = 0
for i in range(2**N):
    cnt = 0
    for j in range(N):
        ok = True
        if i >> j & 1:
            cnt += 1
            for k in range(len(xy[j])):
                if (i >> (xy[j][k][0] - 1) & 1) != xy[j][k][1]:
                    ok = False
                    break
        if ok == False:
            cnt = 0
            break
    res = max(res, cnt)
print(res)

import sys, heapq, bisect, math, fractions
from collections import deque

N = int(eval(input()))
xy = [[] for _ in range(N)]
for i in range(N):
    a = int(eval(input()))
    for _ in range(a):
        xy[i].append(tuple(map(int, input().split())))


def ok(i: int, j: int):
    for x, y in xy[j]:
        if y == 0 and (i >> (x - 1) & 1 == 1):
            return False
        if y == 1 and (i >> (x - 1) & 1 == 0):
            return False
    return True


res = 0
for i in range(2**N):
    cnt = 0
    for j in range(N):
        if i >> j & 1 == 1:
            cnt += 1
            if not ok(i, j):
                break
    else:
        res = max(res, cnt)
print(res)

+import sys, heapq, bisect, math, fractions +from collections import deque + -xy = [[] for i in range(N)] +xy = [[] for _ in range(N)] -    A = int(eval(input())) -    for j in range(A): -        x, y = list(map(int, input().split())) -        xy[i].append([x, y]) +    a = int(eval(input())) +    for _ in range(a): +        xy[i].append(tuple(map(int, input().split()))) + + +def ok(i: int, j: int): +    for x, y in xy[j]: +        if y == 0 and (i >> (x - 1) & 1 == 1): +            return False +        if y == 1 and (i >> (x - 1) & 1 == 0): +            return False +    return True + + -        ok = True -        if i >> j & 1: +        if i >> j & 1 == 1: -            for k in range(len(xy[j])): -                if (i >> (xy[j][k][0] - 1) & 1) != xy[j][k][1]: -                    ok = False -                    break -        if ok == False: -            cnt = 0 -            break -    res = max(res, cnt) +            if not ok(i, j): +                break +    else: +        res = max(res, cnt)