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, len(h))

    print(ans)





if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline





def main():

    N = int(eval(input()))

    H = [0]*N

    U = [0]*N

    for i in range(N):

        m = int(eval(input()))

        for j in range(m):

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

            x -= 1

            if y:

                H[i] += (1 << x)

            else:

                U[i] += (1 << x)



    ans = 0

    for i in range(1 << N):

        h, u = 0, 0

        for j in range(N):

            if (i >> j) & 1:

                h |= (1 << j)

                h |= H[j]

                u |= U[j]

            else:

                u |= (1 << j)

        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, len(h))
    print(ans)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    H = [0] * N
    U = [0] * N
    for i in range(N):
        m = int(eval(input()))
        for j in range(m):
            x, y = list(map(int, input().split()))
            x -= 1
            if y:
                H[i] += 1 << x
            else:
                U[i] += 1 << x
    ans = 0
    for i in range(1 << N):
        h, u = 0, 0
        for j in range(N):
            if (i >> j) & 1:
                h |= 1 << j
                h |= H[j]
                u |= U[j]
            else:
                u |= 1 << j
        if not (h & u):
            ans = max(ans, bin(i).count("1"))
    print(ans)


if __name__ == "__main__":
    main()

-    A = [[set(), set()] for _ in range(N)] +    H = [0] * N +    U = [0] * N -            A[i][y].add(x) +            x -= 1 +            if y: +                H[i] += 1 << x +            else: +                U[i] += 1 << x -        h, u = set(), set() +        h, u = 0, 0 -                h.add(j + 1) -                h |= A[j][1] -                u |= A[j][0] +                h |= 1 << j +                h |= H[j] +                u |= U[j] -                u.add(j + 1) +                u |= 1 << j -            ans = max(ans, len(h)) +            ans = max(ans, bin(i).count("1"))