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

                else:

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

                        ok = False

    if ok:

        ans = max(ans, honest)

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()))
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
                else:
                    if not bit & (1 << X[i][j]):
                        ok = False
    if ok:
        ans = max(ans, honest)
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)

+                        break +                        break +            if not ok: +                break