from itertools import combinations



n = int(eval(input()))

l = (1 << n) - 1

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



def fail(x):

  x = sum(1 << i for i in x)

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



while all(map(fail, combinations(r, n))):

  n -= 1

print(n)

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)

from itertools import combinations

n = int(eval(input()))
l = (1 << n) - 1
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


def fail(x):
    x = sum(1 << i for i in x)
    return not all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1)


while all(map(fail, combinations(r, n))):
    n -= 1
print(n)

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)

-from itertools import combinations +from itertools import combinations, count -l = (1 << n) - 1 -a = [[0, 0] for _ in r] +a = [(set(), set()) for _ in r] -        a[i][y] |= 1 << x - 1 - - -def fail(x): -    x = sum(1 << i for i in x) -    return not all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1) - - -while all(map(fail, combinations(r, n))): -    n -= 1 -print(n) +        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)