import itertools

 

n=int(eval(input()))

H,L=[[] for _ in range(n)],[[] for _ in range(n)]

 

for i in range(n):

  m=int(eval(input()))

  for j in range(m):

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

    if y==1:

      H[i].append(x-1)

    else:

      L[i].append(x-1)

      

N=set(range(n))

ans=0

pat=set()

for num in range(1,n+1):

  pat=pat|set(itertools.combinations(list(range(n)),num))

for h in pat:

    h=set(h)

    num=len(h)

    nh=N-h

    t=sum([H[i] for i in h],[])

    l=sum([L[i] for i in h],[])

    if set(t)<=h and set(l)<=nh:

      ans=max(ans,num)

print(ans)
import itertools

 

n=int(eval(input()))

H,L=[[] for _ in range(n)],[[] for _ in range(n)]

 

for i in range(n):

  m=int(eval(input()))

  for j in range(m):

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

    if y==1:

      H[i].append(x-1)

    else:

      L[i].append(x-1)

      

N=set(range(n))

ans=0

for num in range(1,n+1):

  pat=set(itertools.combinations(list(range(n)),num))

  for h in pat:

      h=set(h)

      num=len(h)

      nh=N-h

      t=sum([H[i] for i in h],[])

      l=sum([L[i] for i in h],[])

      if set(t)<=h and set(l)<=nh:

        ans=max(ans,num)

print(ans)
import itertools

n = int(eval(input()))
H, L = [[] for _ in range(n)], [[] for _ in range(n)]
for i in range(n):
    m = int(eval(input()))
    for j in range(m):
        x, y = list(map(int, input().split()))
        if y == 1:
            H[i].append(x - 1)
        else:
            L[i].append(x - 1)
N = set(range(n))
ans = 0
pat = set()
for num in range(1, n + 1):
    pat = pat | set(itertools.combinations(list(range(n)), num))
for h in pat:
    h = set(h)
    num = len(h)
    nh = N - h
    t = sum([H[i] for i in h], [])
    l = sum([L[i] for i in h], [])
    if set(t) <= h and set(l) <= nh:
        ans = max(ans, num)
print(ans)

import itertools

n = int(eval(input()))
H, L = [[] for _ in range(n)], [[] for _ in range(n)]
for i in range(n):
    m = int(eval(input()))
    for j in range(m):
        x, y = list(map(int, input().split()))
        if y == 1:
            H[i].append(x - 1)
        else:
            L[i].append(x - 1)
N = set(range(n))
ans = 0
for num in range(1, n + 1):
    pat = set(itertools.combinations(list(range(n)), num))
    for h in pat:
        h = set(h)
        num = len(h)
        nh = N - h
        t = sum([H[i] for i in h], [])
        l = sum([L[i] for i in h], [])
        if set(t) <= h and set(l) <= nh:
            ans = max(ans, num)
print(ans)

-pat = set() -    pat = pat | set(itertools.combinations(list(range(n)), num)) -for h in pat: -    h = set(h) -    num = len(h) -    nh = N - h -    t = sum([H[i] for i in h], []) -    l = sum([L[i] for i in h], []) -    if set(t) <= h and set(l) <= nh: -        ans = max(ans, num) +    pat = set(itertools.combinations(list(range(n)), num)) +    for h in pat: +        h = set(h) +        num = len(h) +        nh = N - h +        t = sum([H[i] for i in h], []) +        l = sum([L[i] for i in h], []) +        if set(t) <= h and set(l) <= nh: +            ans = max(ans, num)