from itertools import combinations



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)



fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1].issubset(x) for i in x)



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

  n -= 1

print(n)

from itertools import combinations



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)



fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1] < x for i in x)



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

  n -= 1

print(n)

from itertools import combinations

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)
fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1].issubset(x) for i in x)
while all(map(fail, combinations(r, n))):
    n -= 1
print(n)

from itertools import combinations

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)
fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1] < x for i in x)
while all(map(fail, list(map(set, combinations(r, n))))):
    n -= 1
print(n)

-fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1].issubset(x) for i in x) -while all(map(fail, combinations(r, n))): +fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1] < x for i in x) +while all(map(fail, list(map(set, combinations(r, n))))):