N = int(eval(input()))

A = [0] * N

XY = []



for i in range(N):

    tmp = []

    a = int(eval(input()))

    A[i] = a

    for j in range(a):

        tmp.append(list(map(int, input().split())))

    XY.append(tmp)



def counter(x):

    if x == 0:

        return 0

    else:

        return counter(x >> 1) + (x & 1)



ans = 0

for bits in range(1, 1 << N):

    ok = True

    for i in range(N):

        if not (bits & (1 << i)):

            continue

            

        for x, y in XY[i]:

            if ((bits >> (x - 1)) & 1) ^ y:

                ok = False

                

    if ok:

        ans = max(ans, counter(bits))

            

print(ans)

N = int(eval(input()))

X = {}



for i in range(N):

    A = int(eval(input()))

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

    X[i] = tmp



ans = 0

for bit in range(2 ** N):

    tmp = bit

    flag = True

    for i in range(N):

        if not (bit >> i & 1):

            continue



        for x, y in X[i]:

            if (bit >> (x - 1) & 1) != y:

                flag = False

                break

                

    if flag:

        ans = max(ans, bin(bit).count("1"))



print(ans)

N = int(eval(input()))
A = [0] * N
XY = []
for i in range(N):
    tmp = []
    a = int(eval(input()))
    A[i] = a
    for j in range(a):
        tmp.append(list(map(int, input().split())))
    XY.append(tmp)


def counter(x):
    if x == 0:
        return 0
    else:
        return counter(x >> 1) + (x & 1)


ans = 0
for bits in range(1, 1 << N):
    ok = True
    for i in range(N):
        if not (bits & (1 << i)):
            continue
        for x, y in XY[i]:
            if ((bits >> (x - 1)) & 1) ^ y:
                ok = False
    if ok:
        ans = max(ans, counter(bits))
print(ans)

N = int(eval(input()))
X = {}
for i in range(N):
    A = int(eval(input()))
    tmp = [list(map(int, input().split())) for _ in range(A)]
    X[i] = tmp
ans = 0
for bit in range(2**N):
    tmp = bit
    flag = True
    for i in range(N):
        if not (bit >> i & 1):
            continue
        for x, y in X[i]:
            if (bit >> (x - 1) & 1) != y:
                flag = False
                break
    if flag:
        ans = max(ans, bin(bit).count("1"))
print(ans)

-A = [0] * N -XY = [] +X = {} -    tmp = [] -    a = int(eval(input())) -    A[i] = a -    for j in range(a): -        tmp.append(list(map(int, input().split()))) -    XY.append(tmp) - - -def counter(x): -    if x == 0: -        return 0 -    else: -        return counter(x >> 1) + (x & 1) - - +    A = int(eval(input())) +    tmp = [list(map(int, input().split())) for _ in range(A)] +    X[i] = tmp -for bits in range(1, 1 << N): -    ok = True +for bit in range(2**N): +    tmp = bit +    flag = True -        if not (bits & (1 << i)): +        if not (bit >> i & 1): -        for x, y in XY[i]: -            if ((bits >> (x - 1)) & 1) ^ y: -                ok = False -    if ok: -        ans = max(ans, counter(bits)) +        for x, y in X[i]: +            if (bit >> (x - 1) & 1) != y: +                flag = False +                break +    if flag: +        ans = max(ans, bin(bit).count("1"))