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, u = set(), set()

        for j in range(N):

            if (i >> j) & 1:

                h.add(j+1)

            else:

                u.add(j+1)

        for k in list(h):

            h |= A[k-1][1]

            u |= A[k-1][0]

        if not (h & u):

            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, u = set(), set()

        for j in range(N):

            if (i >> j) & 1:

                h.add(j+1)

                h |= A[j][1]

                u |= A[j][0]

            else:

                u.add(j+1)

        if not (h & u):

            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, u = set(), set()
        for j in range(N):
            if (i >> j) & 1:
                h.add(j + 1)
            else:
                u.add(j + 1)
        for k in list(h):
            h |= A[k - 1][1]
            u |= A[k - 1][0]
        if not (h & u):
            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, u = set(), set()
        for j in range(N):
            if (i >> j) & 1:
                h.add(j + 1)
                h |= A[j][1]
                u |= A[j][0]
            else:
                u.add(j + 1)
        if not (h & u):
            ans = max(ans, bin(i).count("1"))
    print(ans)


if __name__ == "__main__":
    main()

+                h |= A[j][1] +                u |= A[j][0] -        for k in list(h): -            h |= A[k - 1][1] -            u |= A[k - 1][0]