N = int(eval(input()))

xyss = []

for i in range(N):

    A = int(eval(input()))

    xys = []

    for j in range(A):

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

        xys.append((x-1, y))

    xyss.append(xys)



ans = 0

for S in range(2**N):

    numHonest = 0

    isOK = True

    for i in range(N):  # 人i

        if (S>>i)&1 == 0:

            continue



        numHonest += 1

        xys = xyss[i]

        A = len(xys)

        for x, y in xys:  # 証言j

            if (S>>x)&1 != y:

                isOK = False

                break

        if not isOK:

            break



    if isOK:

        ans = max(ans, numHonest)



print(ans)

N = int(eval(input()))

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

for i in range(N):

    A = int(eval(input()))

    for _ in range(A):

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

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



ans = 0

for ptn in range(1<<N):

    conflict = False

    for i in range(N):

        if (ptn>>i) & 1:

            for x, y in xyss[i]:

                if (ptn>>x) & 1 != y:

                    conflict = True

                    break

        if conflict:

            break

    else:

        num1 = bin(ptn).count('1')

        if num1 > ans:

            ans = num1



print(ans)

N = int(eval(input()))
xyss = []
for i in range(N):
    A = int(eval(input()))
    xys = []
    for j in range(A):
        x, y = list(map(int, input().split()))
        xys.append((x - 1, y))
    xyss.append(xys)
ans = 0
for S in range(2**N):
    numHonest = 0
    isOK = True
    for i in range(N):  # 人i
        if (S >> i) & 1 == 0:
            continue
        numHonest += 1
        xys = xyss[i]
        A = len(xys)
        for x, y in xys:  # 証言j
            if (S >> x) & 1 != y:
                isOK = False
                break
        if not isOK:
            break
    if isOK:
        ans = max(ans, numHonest)
print(ans)

N = int(eval(input()))
xyss = [[] for _ in range(N)]
for i in range(N):
    A = int(eval(input()))
    for _ in range(A):
        x, y = list(map(int, input().split()))
        xyss[i].append((x - 1, y))
ans = 0
for ptn in range(1 << N):
    conflict = False
    for i in range(N):
        if (ptn >> i) & 1:
            for x, y in xyss[i]:
                if (ptn >> x) & 1 != y:
                    conflict = True
                    break
        if conflict:
            break
    else:
        num1 = bin(ptn).count("1")
        if num1 > ans:
            ans = num1
print(ans)

-xyss = [] +xyss = [[] for _ in range(N)] -    xys = [] -    for j in range(A): +    for _ in range(A): -        xys.append((x - 1, y)) -    xyss.append(xys) +        xyss[i].append((x - 1, y)) -for S in range(2**N): -    numHonest = 0 -    isOK = True -    for i in range(N):  # 人i -        if (S >> i) & 1 == 0: -            continue -        numHonest += 1 -        xys = xyss[i] -        A = len(xys) -        for x, y in xys:  # 証言j -            if (S >> x) & 1 != y: -                isOK = False -                break -        if not isOK: +for ptn in range(1 << N): +    conflict = False +    for i in range(N): +        if (ptn >> i) & 1: +            for x, y in xyss[i]: +                if (ptn >> x) & 1 != y: +                    conflict = True +                    break +        if conflict: -    if isOK: -        ans = max(ans, numHonest) +    else: +        num1 = bin(ptn).count("1") +        if num1 > ans: +            ans = num1