import sys

input = sys.stdin.readline



n = int(eval(input()))

la, lxy = [], []

for i in range(n):

  a = int(eval(input()))

  la.append(a)

  xy = []

  for j in range(a):

    xy.append(list(map(int, input().split())))

  lxy.append(xy)



from itertools import product



lb = [''.join(b) for b in product('01', repeat=n)]

lc = [sum(int(j) for j in i) for i in lb]

lc, lb = list(zip(*sorted(zip(lc, lb), reverse=True)))

lb = [[int(j) for j in i] for i in lb]



for l in lb:

  ok = 1

  for i in range(n):

    a = la[i]

    for j in range(a):

      x, y = lxy[i][j]

      if l[i] == 1 and l[x-1] != y:

        ok = 0

        break

  if ok:

    print((sum(int(k) for k in l)))

    break

else:

  print((0))
import sys, itertools

input = sys.stdin.readline



n = int(eval(input()))

ll = []

for i in range(n):

  a = int(eval(input()))

  for j in range(a):

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

    ll.append([i, x-1, y])



ans = 0



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

  ok = 1

  for l in ll:

    if p[l[0]] == 1 and p[l[1]] != l[2]:

      ok = 0

      break

  if ok:

    ans = max(ans, sum(p))



print(ans)
import sys

input = sys.stdin.readline
n = int(eval(input()))
la, lxy = [], []
for i in range(n):
    a = int(eval(input()))
    la.append(a)
    xy = []
    for j in range(a):
        xy.append(list(map(int, input().split())))
    lxy.append(xy)
from itertools import product

lb = ["".join(b) for b in product("01", repeat=n)]
lc = [sum(int(j) for j in i) for i in lb]
lc, lb = list(zip(*sorted(zip(lc, lb), reverse=True)))
lb = [[int(j) for j in i] for i in lb]
for l in lb:
    ok = 1
    for i in range(n):
        a = la[i]
        for j in range(a):
            x, y = lxy[i][j]
            if l[i] == 1 and l[x - 1] != y:
                ok = 0
                break
    if ok:
        print((sum(int(k) for k in l)))
        break
else:
    print((0))

import sys, itertools

input = sys.stdin.readline
n = int(eval(input()))
ll = []
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        ll.append([i, x - 1, y])
ans = 0
for p in itertools.product([1, 0], repeat=n):
    ok = 1
    for l in ll:
        if p[l[0]] == 1 and p[l[1]] != l[2]:
            ok = 0
            break
    if ok:
        ans = max(ans, sum(p))
print(ans)

-import sys +import sys, itertools -la, lxy = [], [] +ll = [] -    la.append(a) -    xy = [] -        xy.append(list(map(int, input().split()))) -    lxy.append(xy) -from itertools import product - -lb = ["".join(b) for b in product("01", repeat=n)] -lc = [sum(int(j) for j in i) for i in lb] -lc, lb = list(zip(*sorted(zip(lc, lb), reverse=True))) -lb = [[int(j) for j in i] for i in lb] -for l in lb: +        x, y = list(map(int, input().split())) +        ll.append([i, x - 1, y]) +ans = 0 +for p in itertools.product([1, 0], repeat=n): -    for i in range(n): -        a = la[i] -        for j in range(a): -            x, y = lxy[i][j] -            if l[i] == 1 and l[x - 1] != y: -                ok = 0 -                break +    for l in ll: +        if p[l[0]] == 1 and p[l[1]] != l[2]: +            ok = 0 +            break -        print((sum(int(k) for k in l))) -        break -else: -    print((0)) +        ans = max(ans, sum(p)) +print(ans)