def c_honest_or_unkind_2():

    N = int(eval(input()))

    Answers = []

    for _ in range(N):

        a = int(eval(input()))

        Answers.append([[int(i) for i in input().split()] for j in range(a)])



    # print(Answers)

    ret = -1

    for bits in range(1 << N):

        honests = set()

        unkinds = set()

        for k in range(N):

            if (bits >> k) & 1 == 1:

                honests.add(k)

            else:

                unkinds.add(k)

        # print(honests, unkinds, end=' ')

        is_contradict = False

        for k, answer in enumerate(Answers):

            if k not in honests:

                continue



            for x, y in answer:

                x -= 1

                if (y == 1 and x in unkinds) or (y == 0 and x in honests):

                    # print(k, x, y)

                    is_contradict = True

                    break

            if is_contradict:

                break

        else:

            # print(honests)

            ret = max(ret, len(honests))

    return ret



print((c_honest_or_unkind_2()))
def c_honest_or_unkind_2():

    N = int(eval(input()))

    Answers = []

    for _ in range(N):

        a = int(eval(input()))

        Answers.append([[int(i) for i in input().split()] for j in range(a)])



    ret = -1

    for bits in range(1 << N):

        honests = set()

        for k in range(N):

            if (bits >> k) & 1 == 1:

                honests.add(k)



        is_contradict = False

        for k, answer in enumerate(Answers):

            if k not in honests:

                continue  # k 人目は不親切な人としたので証言を調べない



            for x, y in answer:

                x -= 1

                # 証言に矛盾が生じた

                if (y == 0 and x in honests) or (y == 1 and not x in honests):

                    is_contradict = True

                    break

            if is_contradict:

                break  # 1つでも矛盾があれば全証言に矛盾があるとする

        else:

            # 全証言に矛盾がなかったので正直者の人数を更新する

            ret = max(ret, len(honests))

    return ret



print((c_honest_or_unkind_2()))
def c_honest_or_unkind_2():
    N = int(eval(input()))
    Answers = []
    for _ in range(N):
        a = int(eval(input()))
        Answers.append([[int(i) for i in input().split()] for j in range(a)])
    # print(Answers)
    ret = -1
    for bits in range(1 << N):
        honests = set()
        unkinds = set()
        for k in range(N):
            if (bits >> k) & 1 == 1:
                honests.add(k)
            else:
                unkinds.add(k)
        # print(honests, unkinds, end=' ')
        is_contradict = False
        for k, answer in enumerate(Answers):
            if k not in honests:
                continue
            for x, y in answer:
                x -= 1
                if (y == 1 and x in unkinds) or (y == 0 and x in honests):
                    # print(k, x, y)
                    is_contradict = True
                    break
            if is_contradict:
                break
        else:
            # print(honests)
            ret = max(ret, len(honests))
    return ret


print((c_honest_or_unkind_2()))

def c_honest_or_unkind_2():
    N = int(eval(input()))
    Answers = []
    for _ in range(N):
        a = int(eval(input()))
        Answers.append([[int(i) for i in input().split()] for j in range(a)])
    ret = -1
    for bits in range(1 << N):
        honests = set()
        for k in range(N):
            if (bits >> k) & 1 == 1:
                honests.add(k)
        is_contradict = False
        for k, answer in enumerate(Answers):
            if k not in honests:
                continue  # k 人目は不親切な人としたので証言を調べない
            for x, y in answer:
                x -= 1
                # 証言に矛盾が生じた
                if (y == 0 and x in honests) or (y == 1 and not x in honests):
                    is_contradict = True
                    break
            if is_contradict:
                break  # 1つでも矛盾があれば全証言に矛盾があるとする
        else:
            # 全証言に矛盾がなかったので正直者の人数を更新する
            ret = max(ret, len(honests))
    return ret


print((c_honest_or_unkind_2()))

-    # print(Answers) -        unkinds = set() -            else: -                unkinds.add(k) -        # print(honests, unkinds, end=' ') -                continue +                continue  # k 人目は不親切な人としたので証言を調べない -                if (y == 1 and x in unkinds) or (y == 0 and x in honests): -                    # print(k, x, y) +                # 証言に矛盾が生じた +                if (y == 0 and x in honests) or (y == 1 and not x in honests): -                break +                break  # 1つでも矛盾があれば全証言に矛盾があるとする -            # print(honests) +            # 全証言に矛盾がなかったので正直者の人数を更新する