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):

  b=1

  for i,x,y in ll:

    if p>>i&1 and p>>x&1!=y:

      b=0

      break

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

print(c)
import sys,itertools as it

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 it.product([0,1],repeat=n):

  b=1

  for i,x,y in ll:

    if p[i] and p[x]!=y:

      b=0

      break

  if b: 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):
    b = 1
    for i, x, y in ll:
        if p >> i & 1 and p >> x & 1 != y:
            b = 0
            break
    if b:
        c = max(c, sum(p >> i & 1 for i in range(n)))
print(c)

import sys, itertools as it

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 it.product([0, 1], repeat=n):
    b = 1
    for i, x, y in ll:
        if p[i] and p[x] != y:
            b = 0
            break
    if b:
        c = max(c, sum(p))
print(c)

-import sys +import sys, itertools as it -for p in range(2**n): +for p in it.product([0, 1], repeat=n): -        if p >> i & 1 and p >> x & 1 != y: +        if p[i] and p[x] != y: -        c = max(c, sum(p >> i & 1 for i in range(n))) +        c = max(c, sum(p))