import sys

input=sys.stdin.readline

n=int(eval(input()))

ll=[]

for i in range(n):

  a=int(eval(input()))

  for _ in range(a):

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

    ll+=[(i,x-1,y)]

c=0

for p in range(2**n):

  if all(p>>i&1<1 or p>>x&1==y for i,x,y in ll):

    c=max(c,sum(p>>i&1 for i in range(n)))

print(c)
import sys,itertools as it

f=sys.stdin.readline

n=int(f())

ll=[]

for i in range(n):

  a=int(f())

  for _ in range(a):

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

    ll+=[(i,x-1,y)]

c=0

for p in it.product([0,1],repeat=n):

  if all(p[i]<1 or p[x]==y for i,x,y in ll):

    c=max(c,sum(p))

print(c)
import sys

input = sys.stdin.readline
n = int(eval(input()))
ll = []
for i in range(n):
    a = int(eval(input()))
    for _ in range(a):
        x, y = list(map(int, input().split()))
        ll += [(i, x - 1, y)]
c = 0
for p in range(2**n):
    if all(p >> i & 1 < 1 or p >> x & 1 == y for i, x, y in ll):
        c = max(c, sum(p >> i & 1 for i in range(n)))
print(c)

import sys, itertools as it

f = sys.stdin.readline
n = int(f())
ll = []
for i in range(n):
    a = int(f())
    for _ in range(a):
        x, y = list(map(int, f().split()))
        ll += [(i, x - 1, y)]
c = 0
for p in it.product([0, 1], repeat=n):
    if all(p[i] < 1 or p[x] == y for i, x, y in ll):
        c = max(c, sum(p))
print(c)

-import sys +import sys, itertools as it -input = sys.stdin.readline -n = int(eval(input())) +f = sys.stdin.readline +n = int(f()) -    a = int(eval(input())) +    a = int(f()) -        x, y = list(map(int, input().split())) +        x, y = list(map(int, f().split())) -for p in range(2**n): -    if all(p >> i & 1 < 1 or p >> x & 1 == y for i, x, y in ll): -        c = max(c, sum(p >> i & 1 for i in range(n))) +for p in it.product([0, 1], repeat=n): +    if all(p[i] < 1 or p[x] == y for i, x, y in ll): +        c = max(c, sum(p))