def popcount(x):

  r, q = 0, x

  while x:

    r += 1

    x &= x - 1

  return r, q

 

n = int(eval(input()))

r = list(range(n))

a = [[0, 0] for _ in r]

for i in r:

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

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

    a[i][y] |= 1 << (x - 1)

l = (1 << n) - 1 

b = sorted(map(popcount, list(range(1, l + 1))))

ans = next((i for i, x in reversed(b)

           if all(a[j][0] & x == a[j][1] & l - x == 0 for j in r if x >> j & 1)), 0)

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)

r = 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(r)

def popcount(x):
    r, q = 0, x
    while x:
        r += 1
        x &= x - 1
    return r, q


n = int(eval(input()))
r = list(range(n))
a = [[0, 0] for _ in r]
for i in r:
    for _ in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        a[i][y] |= 1 << (x - 1)
l = (1 << n) - 1
b = sorted(map(popcount, list(range(1, l + 1))))
ans = next(
    (
        i
        for i, x in reversed(b)
        if all(a[j][0] & x == a[j][1] & l - x == 0 for j in r if x >> j & 1)
    ),
    0,
)
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)
r = 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(r)

-def popcount(x): -    r, q = 0, x -    while x: -        r += 1 -        x &= x - 1 -    return r, q - +from itertools import combinations, count -a = [[0, 0] for _ in r] +a = [(set(), set()) for _ in r] -        a[i][y] |= 1 << (x - 1) -l = (1 << n) - 1 -b = sorted(map(popcount, list(range(1, l + 1)))) -ans = next( -    ( -        i -        for i, x in reversed(b) -        if all(a[j][0] & x == a[j][1] & l - x == 0 for j in r if x >> j & 1) -    ), -    0, +        a[i][y].add(x - 1) +r = 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) +print(r)