import sys

input = sys.stdin.readline

N, = list(map(int, input().split()))

rs = []

for _ in range(N):

    A, = list(map(int, input().split()))

    ts, fs = set(), set()

    for _ in range(A):

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

        if y:

            ts.add(x-1)

        else:

            fs.add(x-1)

    rs.append((ts, fs))

r = 0

for i in range(2**N):

    i = i+2**N

    bi = bin(i)[3:]

    ok = True

    for j in range(N):

        if int(bi[j]):

            for t in rs[j][0]:

                if not int(bi[t]):

                    ok = False

            for t in rs[j][1]:

                if int(bi[t]):

                    ok = False

    if ok:

        r = max(r, bi.count("1"))

print(r)

import sys

input = sys.stdin.readline

N, = list(map(int, input().split()))

rs = []

for _ in range(N):

    A, = list(map(int, input().split()))

    ts, fs = set(), set()

    for _ in range(A):

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

        if y:

            ts.add(x-1)

        else:

            fs.add(x-1)

    rs.append((ts, fs))

r = 0

for i in range(2**N):

    ok = True

    c = 0

    for j in range(N):

        if (i>>j) % 2:

            for t in rs[j][0]:

                if not (i>>t) % 2:

                    ok = False

            for t in rs[j][1]:

                if (i>>t) % 2:

                    ok = False

            c += 1

    if ok:

        r = max(r, c)

print(r)

import sys

input = sys.stdin.readline
(N,) = list(map(int, input().split()))
rs = []
for _ in range(N):
    (A,) = list(map(int, input().split()))
    ts, fs = set(), set()
    for _ in range(A):
        x, y = list(map(int, input().split()))
        if y:
            ts.add(x - 1)
        else:
            fs.add(x - 1)
    rs.append((ts, fs))
r = 0
for i in range(2**N):
    i = i + 2**N
    bi = bin(i)[3:]
    ok = True
    for j in range(N):
        if int(bi[j]):
            for t in rs[j][0]:
                if not int(bi[t]):
                    ok = False
            for t in rs[j][1]:
                if int(bi[t]):
                    ok = False
    if ok:
        r = max(r, bi.count("1"))
print(r)

import sys

input = sys.stdin.readline
(N,) = list(map(int, input().split()))
rs = []
for _ in range(N):
    (A,) = list(map(int, input().split()))
    ts, fs = set(), set()
    for _ in range(A):
        x, y = list(map(int, input().split()))
        if y:
            ts.add(x - 1)
        else:
            fs.add(x - 1)
    rs.append((ts, fs))
r = 0
for i in range(2**N):
    ok = True
    c = 0
    for j in range(N):
        if (i >> j) % 2:
            for t in rs[j][0]:
                if not (i >> t) % 2:
                    ok = False
            for t in rs[j][1]:
                if (i >> t) % 2:
                    ok = False
            c += 1
    if ok:
        r = max(r, c)
print(r)

-    i = i + 2**N -    bi = bin(i)[3:] +    c = 0 -        if int(bi[j]): +        if (i >> j) % 2: -                if not int(bi[t]): +                if not (i >> t) % 2: -                if int(bi[t]): +                if (i >> t) % 2: +            c += 1 -        r = max(r, bi.count("1")) +        r = max(r, c)