def popcount(x):

  r = 0

  while x:

    r += 1

    x &= x - 1

  return r

 

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)

 

m = 0

l = (1 << n) - 1

for x in range(1, l + 1):

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

    m = max(m, popcount(x))

print(m)

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)

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


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)
m = 0
l = (1 << n) - 1
for x in range(1, l + 1):
    if all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1):
        m = max(m, popcount(x))
print(m)

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)

-    r = 0 +    r, q = 0, x -    return r +    return r, q -m = 0 -for x in range(1, l + 1): -    if all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1): -        m = max(m, popcount(x)) -print(m) +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)