N = int(eval(input()))

A = [0]*N

X = []

Y = []

for i in range(N):

    A[i] = int(eval(input()))

    X.append([])

    Y.append([])

    for j in range(A[i]):

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

        X[i].append(x-1)

        Y[i].append(y)

ans = 0

for bit in range(1<<N):

    honest = 0

    ok = True

    for i in range(N):

        if bit&(1<<i):

            honest += 1

            for j in range(A[i]):

                if Y[i][j] == 0:

                    if bit&(1<<X[i][j]):

                        ok = False

                        break

                else:

                    if not bit&(1<<X[i][j]):

                        ok = False

                        break

            if not ok:

                break

    if ok:

        ans = max(ans, honest)

print(ans)
N = int(eval(input()))

XY = [[] for _ in range(N)]

for i in range(N):

    A = int(eval(input()))

    for _ in range(A):

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

        XY[i].append((x-1,y))

ans = 0

for bit in range(1<<N):

    cnt = bin(bit).count('1')

    ok = True

    for i in range(N):

        if bit&(1<<i):

            for x,y in XY[i]:

                if y == 1:

                    if not bit&(1<<x):

                        ok = False

                        break

                else:

                    if bit&(1<<x):

                        ok = False

                        break

            if not ok:

                break

    if ok:

        ans = max(ans, cnt)

print(ans)
N = int(eval(input()))
A = [0] * N
X = []
Y = []
for i in range(N):
    A[i] = int(eval(input()))
    X.append([])
    Y.append([])
    for j in range(A[i]):
        x, y = list(map(int, input().split()))
        X[i].append(x - 1)
        Y[i].append(y)
ans = 0
for bit in range(1 << N):
    honest = 0
    ok = True
    for i in range(N):
        if bit & (1 << i):
            honest += 1
            for j in range(A[i]):
                if Y[i][j] == 0:
                    if bit & (1 << X[i][j]):
                        ok = False
                        break
                else:
                    if not bit & (1 << X[i][j]):
                        ok = False
                        break
            if not ok:
                break
    if ok:
        ans = max(ans, honest)
print(ans)

N = int(eval(input()))
XY = [[] for _ in range(N)]
for i in range(N):
    A = int(eval(input()))
    for _ in range(A):
        x, y = list(map(int, input().split()))
        XY[i].append((x - 1, y))
ans = 0
for bit in range(1 << N):
    cnt = bin(bit).count("1")
    ok = True
    for i in range(N):
        if bit & (1 << i):
            for x, y in XY[i]:
                if y == 1:
                    if not bit & (1 << x):
                        ok = False
                        break
                else:
                    if bit & (1 << x):
                        ok = False
                        break
            if not ok:
                break
    if ok:
        ans = max(ans, cnt)
print(ans)

-A = [0] * N -X = [] -Y = [] +XY = [[] for _ in range(N)] -    A[i] = int(eval(input())) -    X.append([]) -    Y.append([]) -    for j in range(A[i]): +    A = int(eval(input())) +    for _ in range(A): -        X[i].append(x - 1) -        Y[i].append(y) +        XY[i].append((x - 1, y)) -    honest = 0 +    cnt = bin(bit).count("1") -            honest += 1 -            for j in range(A[i]): -                if Y[i][j] == 0: -                    if bit & (1 << X[i][j]): +            for x, y in XY[i]: +                if y == 1: +                    if not bit & (1 << x): -                    if not bit & (1 << X[i][j]): +                    if bit & (1 << x): -        ans = max(ans, honest) +        ans = max(ans, cnt)