N = int(eval(input()))

honest = [[] for _ in range(N)]

unkind = [[] for _ in range(N)]

MAX = 0

for i in range(0,N):

    A = int(eval(input()))

    for _ in range(A):

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

        if y == 0:

            unkind[i].append(x-1)

        else:

            honest[i].append(x-1)



for i in range(2**N):

    flg = 1

    for j in range(N):

        if ((i>>j) & 1):

            bool1 = all([(i>>k) & 1 for k in honest[j]])

            bool2 = all([~(i>>k) & 1 for k in unkind[j]])

            if not all([(i>>k) & 1 for k in honest[j]]) or not all([~(i>>k) & 1 for k in unkind[j]]):

                flg =0



    if flg:

        cnt = 0

        num = i

        while num:

            num &= num -1

            cnt += 1

        MAX = max(cnt,MAX) 



print(MAX)




def main():

    N = int(eval(input()))

    A = []

    for i in range(N):

        a = int(eval(input()))

        XY = []

        for _ in range(a):

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

            XY.append((x-1,y))



        A.append(XY)

    # print(A)



    MAX = 0

    for i in range(2**N):

        # print(i)

        flg = 1

        for j in range(N):

            if (i >>j) & 1:

                # print('b')

                for ch in A[j]:

                    # print(i,ch[0],bin(i >> ch[0]),ch[1],(i >> ch[0])^ ch[1])

                    if ((i >> ch[0])^ ch[1])%2 == 1:

                        # print('a',ch[0])

                        flg = 0



        if flg == 1:

            t = bin(i).count('1')

            MAX = max(t,MAX)

        

    print(MAX)







main()
N = int(eval(input()))
honest = [[] for _ in range(N)]
unkind = [[] for _ in range(N)]
MAX = 0
for i in range(0, N):
    A = int(eval(input()))
    for _ in range(A):
        x, y = list(map(int, input().split(" ")))
        if y == 0:
            unkind[i].append(x - 1)
        else:
            honest[i].append(x - 1)
for i in range(2**N):
    flg = 1
    for j in range(N):
        if (i >> j) & 1:
            bool1 = all([(i >> k) & 1 for k in honest[j]])
            bool2 = all([~(i >> k) & 1 for k in unkind[j]])
            if not all([(i >> k) & 1 for k in honest[j]]) or not all(
                [~(i >> k) & 1 for k in unkind[j]]
            ):
                flg = 0
    if flg:
        cnt = 0
        num = i
        while num:
            num &= num - 1
            cnt += 1
        MAX = max(cnt, MAX)
print(MAX)

def main():
    N = int(eval(input()))
    A = []
    for i in range(N):
        a = int(eval(input()))
        XY = []
        for _ in range(a):
            x, y = list(map(int, input().split()))
            XY.append((x - 1, y))
        A.append(XY)
    # print(A)
    MAX = 0
    for i in range(2**N):
        # print(i)
        flg = 1
        for j in range(N):
            if (i >> j) & 1:
                # print('b')
                for ch in A[j]:
                    # print(i,ch[0],bin(i >> ch[0]),ch[1],(i >> ch[0])^ ch[1])
                    if ((i >> ch[0]) ^ ch[1]) % 2 == 1:
                        # print('a',ch[0])
                        flg = 0
        if flg == 1:
            t = bin(i).count("1")
            MAX = max(t, MAX)
    print(MAX)


main()

-N = int(eval(input())) -honest = [[] for _ in range(N)] -unkind = [[] for _ in range(N)] -MAX = 0 -for i in range(0, N): -    A = int(eval(input())) -    for _ in range(A): -        x, y = list(map(int, input().split(" "))) -        if y == 0: -            unkind[i].append(x - 1) -        else: -            honest[i].append(x - 1) -for i in range(2**N): -    flg = 1 -    for j in range(N): -        if (i >> j) & 1: -            bool1 = all([(i >> k) & 1 for k in honest[j]]) -            bool2 = all([~(i >> k) & 1 for k in unkind[j]]) -            if not all([(i >> k) & 1 for k in honest[j]]) or not all( -                [~(i >> k) & 1 for k in unkind[j]] -            ): -                flg = 0 -    if flg: -        cnt = 0 -        num = i -        while num: -            num &= num - 1 -            cnt += 1 -        MAX = max(cnt, MAX) -print(MAX) +def main(): +    N = int(eval(input())) +    A = [] +    for i in range(N): +        a = int(eval(input())) +        XY = [] +        for _ in range(a): +            x, y = list(map(int, input().split())) +            XY.append((x - 1, y)) +        A.append(XY) +    # print(A) +    MAX = 0 +    for i in range(2**N): +        # print(i) +        flg = 1 +        for j in range(N): +            if (i >> j) & 1: +                # print('b') +                for ch in A[j]: +                    # print(i,ch[0],bin(i >> ch[0]),ch[1],(i >> ch[0])^ ch[1]) +                    if ((i >> ch[0]) ^ ch[1]) % 2 == 1: +                        # print('a',ch[0]) +                        flg = 0 +        if flg == 1: +            t = bin(i).count("1") +            MAX = max(t, MAX) +    print(MAX) + + +main()