import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)

from collections import Counter, deque

from collections import defaultdict

from itertools import combinations, permutations, accumulate, groupby, product

from bisect import bisect_left,bisect_right

from heapq import heapify, heappop, heappush

from math import floor, ceil

from operator import itemgetter

def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))

def LI2(): return [int(eval(input())) for i in range(n)]

def MXI(): return [[LI()]for i in range(n)]

def printns(x): print(('\n'.join(x)))

def printni(x): print(('\n'.join(list(map(str,x)))))

inf = 10**17

mod = 10**9 + 7

#s=input().rstrip()

n=I()

lis=[[]for i in range(n)]

for i in range(n):

    u=I()

    for j in range(u):

        a,b=MI()

        lis[i].append([a,b])

#print(lis)

z=[]

for x in range(2**n):

    u=[]

    for j in range(n):

        u.append(x%2)

        x=x>>1

    #print(u)

    count2=0

    for i in range(n):

        if u[i]==1:

            count=0

            for k in range(len(lis[i])):

                if lis[i][k][1]==u[lis[i][k][0]-1]:

                    count+=1

            if count==len(lis[i]):

                count2+=1

    if count2==sum(u):

        z.append(sum(u))

print((max(z)))
# coding: utf-8

# hello worldと表示する

#float型を許すな

#numpyはpythonで

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)

from collections import Counter, deque

from collections import defaultdict

from itertools import combinations, permutations, accumulate, groupby, product

from bisect import bisect_left,bisect_right

from heapq import heapify, heappop, heappush

from math import floor, ceil,pi,factorial,sqrt

from operator import itemgetter

def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))

def LI2(): return [int(eval(input())) for i in range(n)]

def MXI(): return [[LI()]for i in range(n)]

def SI(): return input().rstrip()

def printns(x): print(('\n'.join(x)))

def printni(x): print(('\n'.join(list(map(str,x)))))

inf = 10**17

mod = 10**9 + 7



n=I()

lis=[[] for i in range(n)]

for i in range(n):

    a=I()

    for j in range(a):

        lis[i].append(LI())

#print(lis)

ans=[]

for x in product([0,1],repeat=n):

    count=0

    flag=True

    for j in range(n):

        if x[j]==1:

            count+=1

            for k in range(len(lis[j])):

                if x[lis[j][k][0]-1]!=lis[j][k][1]:

                    flag=False

    if flag==True:

        ans.append(count)

print((max(ans)))

        

        

        

            

        



                
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def LI2():
    return [int(eval(input())) for i in range(n)]


def MXI():
    return [[LI()] for i in range(n)]


def printns(x):
    print(("\n".join(x)))


def printni(x):
    print(("\n".join(list(map(str, x)))))


inf = 10**17
mod = 10**9 + 7
# s=input().rstrip()
n = I()
lis = [[] for i in range(n)]
for i in range(n):
    u = I()
    for j in range(u):
        a, b = MI()
        lis[i].append([a, b])
# print(lis)
z = []
for x in range(2**n):
    u = []
    for j in range(n):
        u.append(x % 2)
        x = x >> 1
    # print(u)
    count2 = 0
    for i in range(n):
        if u[i] == 1:
            count = 0
            for k in range(len(lis[i])):
                if lis[i][k][1] == u[lis[i][k][0] - 1]:
                    count += 1
            if count == len(lis[i]):
                count2 += 1
    if count2 == sum(u):
        z.append(sum(u))
print((max(z)))

# coding: utf-8
# hello worldと表示する
# float型を許すな
# numpyはpythonで
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil, pi, factorial, sqrt
from operator import itemgetter


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def LI2():
    return [int(eval(input())) for i in range(n)]


def MXI():
    return [[LI()] for i in range(n)]


def SI():
    return input().rstrip()


def printns(x):
    print(("\n".join(x)))


def printni(x):
    print(("\n".join(list(map(str, x)))))


inf = 10**17
mod = 10**9 + 7
n = I()
lis = [[] for i in range(n)]
for i in range(n):
    a = I()
    for j in range(a):
        lis[i].append(LI())
# print(lis)
ans = []
for x in product([0, 1], repeat=n):
    count = 0
    flag = True
    for j in range(n):
        if x[j] == 1:
            count += 1
            for k in range(len(lis[j])):
                if x[lis[j][k][0] - 1] != lis[j][k][1]:
                    flag = False
    if flag == True:
        ans.append(count)
print((max(ans)))

+# coding: utf-8 +# hello worldと表示する +# float型を許すな +# numpyはpythonで -from math import floor, ceil +from math import floor, ceil, pi, factorial, sqrt +def SI(): +    return input().rstrip() + + -# s=input().rstrip() -    u = I() -    for j in range(u): -        a, b = MI() -        lis[i].append([a, b]) +    a = I() +    for j in range(a): +        lis[i].append(LI()) -z = [] -for x in range(2**n): -    u = [] +ans = [] +for x in product([0, 1], repeat=n): +    count = 0 +    flag = True -        u.append(x % 2) -        x = x >> 1 -    # print(u) -    count2 = 0 -    for i in range(n): -        if u[i] == 1: -            count = 0 -            for k in range(len(lis[i])): -                if lis[i][k][1] == u[lis[i][k][0] - 1]: -                    count += 1 -            if count == len(lis[i]): -                count2 += 1 -    if count2 == sum(u): -        z.append(sum(u)) -print((max(z))) +        if x[j] == 1: +            count += 1 +            for k in range(len(lis[j])): +                if x[lis[j][k][0] - 1] != lis[j][k][1]: +                    flag = False +    if flag == True: +        ans.append(count) +print((max(ans)))