# ABC147C - HonestOrUnkind2

from itertools import combinations





def main():

    N = int(eval(input()))

    testimonies = [[] for i in range(N + 1)]

    for i in range(1, N + 1):

        A = int(eval(input()))

        for _ in range(A):

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

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



    for cnt_honest in range(N, 0, -1):

        for honest_people in combinations(list(range(1, N + 1)), cnt_honest):

            honest_people = set(honest_people)

            is_consistent = True

            for i in honest_people:

                for x, y in testimonies[i]:

                    if (x in honest_people and not y) or (x not in honest_people and y):

                        is_consistent = False

                        break

                if not is_consistent:

                    break

            if is_consistent:

                print(cnt_honest)

                return

    print((0))





if __name__ == "__main__":

    main()
# ABC147C - HonestOrUnkind2

from itertools import combinations





def main():

    N = int(eval(input()))

    testimonies = [[] for i in range(N + 1)]

    for i in range(1, N + 1):

        A = int(eval(input()))

        for _ in range(A):

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

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



    for cnt_honest in range(N, 0, -1):

        for honest_people in combinations(list(range(1, N + 1)), cnt_honest):

            is_consistent = True

            for i in honest_people:

                for x, y in testimonies[i]:

                    if (x in honest_people and not y) or (x not in honest_people and y):

                        is_consistent = False

                        break

                if not is_consistent:

                    break

            if is_consistent:

                print(cnt_honest)

                return

    print((0))





if __name__ == "__main__":

    main()
# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(eval(input()))
    testimonies = [[] for i in range(N + 1)]
    for i in range(1, N + 1):
        A = int(eval(input()))
        for _ in range(A):
            x, y = list(map(int, input().split()))
            testimonies[i].append((x, y))
    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(list(range(1, N + 1)), cnt_honest):
            honest_people = set(honest_people)
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i]:
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print((0))


if __name__ == "__main__":
    main()

# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(eval(input()))
    testimonies = [[] for i in range(N + 1)]
    for i in range(1, N + 1):
        A = int(eval(input()))
        for _ in range(A):
            x, y = list(map(int, input().split()))
            testimonies[i].append((x, y))
    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(list(range(1, N + 1)), cnt_honest):
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i]:
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print((0))


if __name__ == "__main__":
    main()

-            honest_people = set(honest_people)