import sys

input = sys.stdin.readline

from operator import eq, ne



def readlines(n):

    for _ in range(n):

        x, y = input().split()

        yield int(x)-1, y



def main():

    n = int(eval(input()))

    graph = []



    for _ in range(n):

        a = int(eval(input()))

        graph.append(list(readlines(a)))



    def check(bits):

        for pre_honest, asserts in zip(bits, graph):

            if pre_honest == "0":

                continue

            for x, y in asserts:

                if bits[x] != y:

                    return -1

        

        return len([b for b in bits if b == "1"])



    for i in range(2**n-1, -1, -1):

        bit = format(i, "0{}b".format(n))

        ans = check(bit)

        if ans > -1:

            print(ans)

            return

    

    print((0))



main()

import sys

input = sys.stdin.readline

from itertools import combinations

from operator import contains



def readlines(n):

    for _ in range(n):

        x, y = input().split()

        yield int(x)-1, y=="1"



def main():

    n = int(eval(input()))

    asserts = []



    for _ in range(n):

        a = int(eval(input()))

        asserts.append(list(readlines(a)))



    def check(comb):

        for i in comb:

            for x, y in asserts[i]:

                mujun = contains if not y else lambda a, b: b not in a

                if mujun(comb, x):

                    return -1

        

        return len(comb)



    for i in range(n+1):

        for comb in combinations(list(range(n)), i):

            yield check(set(comb))



    yield 0



print((max(main())))
import sys

input = sys.stdin.readline
from operator import eq, ne


def readlines(n):
    for _ in range(n):
        x, y = input().split()
        yield int(x) - 1, y


def main():
    n = int(eval(input()))
    graph = []
    for _ in range(n):
        a = int(eval(input()))
        graph.append(list(readlines(a)))

    def check(bits):
        for pre_honest, asserts in zip(bits, graph):
            if pre_honest == "0":
                continue
            for x, y in asserts:
                if bits[x] != y:
                    return -1
        return len([b for b in bits if b == "1"])

    for i in range(2**n - 1, -1, -1):
        bit = format(i, "0{}b".format(n))
        ans = check(bit)
        if ans > -1:
            print(ans)
            return
    print((0))


main()

import sys

input = sys.stdin.readline
from itertools import combinations
from operator import contains


def readlines(n):
    for _ in range(n):
        x, y = input().split()
        yield int(x) - 1, y == "1"


def main():
    n = int(eval(input()))
    asserts = []
    for _ in range(n):
        a = int(eval(input()))
        asserts.append(list(readlines(a)))

    def check(comb):
        for i in comb:
            for x, y in asserts[i]:
                mujun = contains if not y else lambda a, b: b not in a
                if mujun(comb, x):
                    return -1
        return len(comb)

    for i in range(n + 1):
        for comb in combinations(list(range(n)), i):
            yield check(set(comb))
    yield 0


print((max(main())))

-from operator import eq, ne +from itertools import combinations +from operator import contains -        yield int(x) - 1, y +        yield int(x) - 1, y == "1" -    graph = [] +    asserts = [] -        graph.append(list(readlines(a))) +        asserts.append(list(readlines(a))) -    def check(bits): -        for pre_honest, asserts in zip(bits, graph): -            if pre_honest == "0": -                continue -            for x, y in asserts: -                if bits[x] != y: +    def check(comb): +        for i in comb: +            for x, y in asserts[i]: +                mujun = contains if not y else lambda a, b: b not in a +                if mujun(comb, x): -        return len([b for b in bits if b == "1"]) +        return len(comb) -    for i in range(2**n - 1, -1, -1): -        bit = format(i, "0{}b".format(n)) -        ans = check(bit) -        if ans > -1: -            print(ans) -            return -    print((0)) +    for i in range(n + 1): +        for comb in combinations(list(range(n)), i): +            yield check(set(comb)) +    yield 0 -main() +print((max(main())))