n = int(eval(input()))

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

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



for i in range(n):

    a = int(eval(input()))

    for j in range(a):

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

        if y == 1:

            t[i].append(x - 1)

        else:

            s[i].append(x - 1)

res = 0

for k in range(pow(2, n)):

    judge = True

    cnt = 0

    for i in range(n):

        if (k >> i) & 1 == 1:

            for e in t[i]:

                if (k >> e) & 1 == 0:

                    judge = False

            for e in s[i]:

                if (k >> e) & 1 == 1:

                    judge = False

            cnt += 1

    if judge:

        res = max(res, cnt)



print(res)
import itertools as it



n = int(eval(input()))

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

val = list(it.product([0, 1], repeat=n))



for i in range(n):

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

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

        x = x - 1

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





def honesty(k, lis, n):

    for i in range(n):

        if k[i] == 1:

            for l, m in lis[i]:

                if k[l] != m:

                    return False

    return True





res = 0

for k in val:

    if honesty(k, lis, n):

        res = max(res, sum(k))

print(res)

n = int(eval(input()))
t = [[] for _ in range(n)]
s = [[] for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        if y == 1:
            t[i].append(x - 1)
        else:
            s[i].append(x - 1)
res = 0
for k in range(pow(2, n)):
    judge = True
    cnt = 0
    for i in range(n):
        if (k >> i) & 1 == 1:
            for e in t[i]:
                if (k >> e) & 1 == 0:
                    judge = False
            for e in s[i]:
                if (k >> e) & 1 == 1:
                    judge = False
            cnt += 1
    if judge:
        res = max(res, cnt)
print(res)

import itertools as it

n = int(eval(input()))
lis = [[] for _ in range(n)]
val = list(it.product([0, 1], repeat=n))
for i in range(n):
    for j in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        x = x - 1
        lis[i].append((x, y))


def honesty(k, lis, n):
    for i in range(n):
        if k[i] == 1:
            for l, m in lis[i]:
                if k[l] != m:
                    return False
    return True


res = 0
for k in val:
    if honesty(k, lis, n):
        res = max(res, sum(k))
print(res)

+import itertools as it + -t = [[] for _ in range(n)] -s = [[] for _ in range(n)] +lis = [[] for _ in range(n)] +val = list(it.product([0, 1], repeat=n)) -    a = int(eval(input())) -    for j in range(a): +    for j in range(int(eval(input()))): -        if y == 1: -            t[i].append(x - 1) -        else: -            s[i].append(x - 1) +        x = x - 1 +        lis[i].append((x, y)) + + +def honesty(k, lis, n): +    for i in range(n): +        if k[i] == 1: +            for l, m in lis[i]: +                if k[l] != m: +                    return False +    return True + + -for k in range(pow(2, n)): -    judge = True -    cnt = 0 -    for i in range(n): -        if (k >> i) & 1 == 1: -            for e in t[i]: -                if (k >> e) & 1 == 0: -                    judge = False -            for e in s[i]: -                if (k >> e) & 1 == 1: -                    judge = False -            cnt += 1 -    if judge: -        res = max(res, cnt) +for k in val: +    if honesty(k, lis, n): +        res = max(res, sum(k))