import sys

sys.setrecursionlimit(10**9)

N = int(eval(input()))

A = [[] for i in range(N)]



def check(target):

    one_count = 0

    cans = 0

    for idx, flag in enumerate(target):

        if flag == "1":

            one_count += 1

            for x, y in A[idx]:

                if int(target[x]) != y:

                    return 0

    

    cans = max(cans, one_count)

    return cans



def dns(S):

    ans = 0

    if len(S) == N:

        ans = max(ans, check(S))

    else:

        ans = max(dns(S+"0"), dns(S+"1"))

    

    return ans



for i in range(N):

    m = int(eval(input()))

    for j in range(m):

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

        x -= 1

        A[i].append((x, y))



kotae = dns("")



print(kotae)
import sys

def input() : return sys.stdin.readline().strip()



def main():

    ans = 0

    N = int(eval(input()))

    test = []

    for _ in range(N):

        A = int(eval(input()))

        temp = [tuple(map(int, input().split())) for _ in range(A)]

        test.append(temp) 

    

    # bit full search

    print()

    for bit in range(1<<N):

        isOK = True

        for i in range(N):

            if bit & (1<<i):

                for j, flag in test[i]:

                    j -= 1

                    if flag ^ ((bit>>j) & 1):

                        isOK = False

                        break

        if isOK:

            ans = max(ans, bin(bit).count("1"))

    

    print(ans)



            

if __name__ == "__main__":

    main()
import sys

sys.setrecursionlimit(10**9)
N = int(eval(input()))
A = [[] for i in range(N)]


def check(target):
    one_count = 0
    cans = 0
    for idx, flag in enumerate(target):
        if flag == "1":
            one_count += 1
            for x, y in A[idx]:
                if int(target[x]) != y:
                    return 0
    cans = max(cans, one_count)
    return cans


def dns(S):
    ans = 0
    if len(S) == N:
        ans = max(ans, check(S))
    else:
        ans = max(dns(S + "0"), dns(S + "1"))
    return ans


for i in range(N):
    m = int(eval(input()))
    for j in range(m):
        x, y = list(map(int, input().split()))
        x -= 1
        A[i].append((x, y))
kotae = dns("")
print(kotae)

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    ans = 0
    N = int(eval(input()))
    test = []
    for _ in range(N):
        A = int(eval(input()))
        temp = [tuple(map(int, input().split())) for _ in range(A)]
        test.append(temp)
    # bit full search
    print()
    for bit in range(1 << N):
        isOK = True
        for i in range(N):
            if bit & (1 << i):
                for j, flag in test[i]:
                    j -= 1
                    if flag ^ ((bit >> j) & 1):
                        isOK = False
                        break
        if isOK:
            ans = max(ans, bin(bit).count("1"))
    print(ans)


if __name__ == "__main__":
    main()

-sys.setrecursionlimit(10**9) -N = int(eval(input())) -A = [[] for i in range(N)] + +def input(): +    return sys.stdin.readline().strip() -def check(target): -    one_count = 0 -    cans = 0 -    for idx, flag in enumerate(target): -        if flag == "1": -            one_count += 1 -            for x, y in A[idx]: -                if int(target[x]) != y: -                    return 0 -    cans = max(cans, one_count) -    return cans +def main(): +    ans = 0 +    N = int(eval(input())) +    test = [] +    for _ in range(N): +        A = int(eval(input())) +        temp = [tuple(map(int, input().split())) for _ in range(A)] +        test.append(temp) +    # bit full search +    print() +    for bit in range(1 << N): +        isOK = True +        for i in range(N): +            if bit & (1 << i): +                for j, flag in test[i]: +                    j -= 1 +                    if flag ^ ((bit >> j) & 1): +                        isOK = False +                        break +        if isOK: +            ans = max(ans, bin(bit).count("1")) +    print(ans) -def dns(S): -    ans = 0 -    if len(S) == N: -        ans = max(ans, check(S)) -    else: -        ans = max(dns(S + "0"), dns(S + "1")) -    return ans - - -for i in range(N): -    m = int(eval(input())) -    for j in range(m): -        x, y = list(map(int, input().split())) -        x -= 1 -        A[i].append((x, y)) -kotae = dns("") -print(kotae) +if __name__ == "__main__": +    main()