import sys

input = sys.stdin.readline





def main():

    N = int(eval(input()))

    A = [[set(), set()] for _ in range(N)]

    for i in range(N):

        m = int(eval(input()))

        for j in range(m):

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

            A[i][y].add(x)



    ans = 0

    for i in range(1 << N):

        h = set()

        u = set()

        for j in range(N):

            if (i >> j) & 1:

                h.add(j+1)

            else:

                u.add(j+1)

        b = True

        for k in list(h):

            k -= 1

            h |= A[k][1]

            u |= A[k][0]

            if h & u:

                b = False

        if b:

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

    print(ans)





if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline





def main():

    N = int(eval(input()))

    A = [[set(), set()] for _ in range(N)]

    for i in range(N):

        m = int(eval(input()))

        for j in range(m):

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

            A[i][y].add(x)



    ans = 0

    for i in range(1 << N):

        h = set()

        u = set()

        for j in range(N):

            if (i >> j) & 1:

                h.add(j+1)

            else:

                u.add(j+1)

        b = True

        for k in list(h):

            k -= 1

            h |= A[k][1]

            u |= A[k][0]

            if h & u:

                b = False

                break

        if b:

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

    print(ans)





if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    A = [[set(), set()] for _ in range(N)]
    for i in range(N):
        m = int(eval(input()))
        for j in range(m):
            x, y = list(map(int, input().split()))
            A[i][y].add(x)
    ans = 0
    for i in range(1 << N):
        h = set()
        u = set()
        for j in range(N):
            if (i >> j) & 1:
                h.add(j + 1)
            else:
                u.add(j + 1)
        b = True
        for k in list(h):
            k -= 1
            h |= A[k][1]
            u |= A[k][0]
            if h & u:
                b = False
        if b:
            ans = max(ans, bin(i).count("1"))
    print(ans)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    A = [[set(), set()] for _ in range(N)]
    for i in range(N):
        m = int(eval(input()))
        for j in range(m):
            x, y = list(map(int, input().split()))
            A[i][y].add(x)
    ans = 0
    for i in range(1 << N):
        h = set()
        u = set()
        for j in range(N):
            if (i >> j) & 1:
                h.add(j + 1)
            else:
                u.add(j + 1)
        b = True
        for k in list(h):
            k -= 1
            h |= A[k][1]
            u |= A[k][0]
            if h & u:
                b = False
                break
        if b:
            ans = max(ans, bin(i).count("1"))
    print(ans)


if __name__ == "__main__":
    main()

+                break