from itertools import combinations, count



n = int(eval(input()))

r = list(range(n))

a = [(set(), set()) for _ in r]

for i in r:

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

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

    a[i][y].add(x - 1)

ans = next(i for i in count(n, - 1) for x in combinations(r, i)

           if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x))

print(ans)

from itertools import combinations, count



n = int(eval(input()))

r = list(range(n))

a = [(set(), set()) for _ in r]

for i in r:

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

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

    a[i][y].add(x - 1)

ans = next(i for i in count(n, - 1) for x in map(set, combinations(r, i))

           if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x))

print(ans)

from itertools import combinations, count

n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
    for _ in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        a[i][y].add(x - 1)
ans = next(
    i
    for i in count(n, -1)
    for x in combinations(r, i)
    if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x)
)
print(ans)

from itertools import combinations, count

n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
    for _ in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        a[i][y].add(x - 1)
ans = next(
    i
    for i in count(n, -1)
    for x in map(set, combinations(r, i))
    if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)
)
print(ans)

-    for x in combinations(r, i) -    if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x) +    for x in map(set, combinations(r, i)) +    if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)