N = int(eval(input()))

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

for i in range(N):

    Ai = int(eval(input()))

    for _ in range(Ai):

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

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





def countBit(x):

    if x == 0:

        return 0

    else:

        return countBit(x >> 1) + (x & 1)





res = 0

for bits in range(2 ** N):

    bits_ = bin(bits)

    consistency = True

    for i, testimony in enumerate(A):

        if not ((bits >> i) & 1):

            continue

        for t in testimony:

            if ((bits >> t[0]) & 1) ^ t[1]:

                consistency = False



    if consistency:

        res = max(res, countBit(bits))



print(res)

N = int(eval(input()))

A = [[set() for _ in range(2)] for _ in range(N)]

for i in range(N):

    Ai = int(eval(input()))

    for _ in range(Ai):

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

        A[i][y].add(x - 1)



ans = 0

for bit in range(1 << N):

    truth = set()

    false = set()

    ppl_truth = set()

    ppl_false = set()

    for i in range(N):

        if (bit >> i) & 1:

            ppl_truth.add(i)

            truth |= A[i][1]

            false |= A[i][0]

        else:

            ppl_false.add(i)

    if ppl_truth >= truth and ppl_false >= false:

        ans = max(ans, len(ppl_truth))



print(ans)

N = int(eval(input()))
A = [[] for _ in range(N)]
for i in range(N):
    Ai = int(eval(input()))
    for _ in range(Ai):
        x, y = list(map(int, input().split()))
        A[i].append((x - 1, y))


def countBit(x):
    if x == 0:
        return 0
    else:
        return countBit(x >> 1) + (x & 1)


res = 0
for bits in range(2**N):
    bits_ = bin(bits)
    consistency = True
    for i, testimony in enumerate(A):
        if not ((bits >> i) & 1):
            continue
        for t in testimony:
            if ((bits >> t[0]) & 1) ^ t[1]:
                consistency = False
    if consistency:
        res = max(res, countBit(bits))
print(res)

N = int(eval(input()))
A = [[set() for _ in range(2)] for _ in range(N)]
for i in range(N):
    Ai = int(eval(input()))
    for _ in range(Ai):
        x, y = list(map(int, input().split()))
        A[i][y].add(x - 1)
ans = 0
for bit in range(1 << N):
    truth = set()
    false = set()
    ppl_truth = set()
    ppl_false = set()
    for i in range(N):
        if (bit >> i) & 1:
            ppl_truth.add(i)
            truth |= A[i][1]
            false |= A[i][0]
        else:
            ppl_false.add(i)
    if ppl_truth >= truth and ppl_false >= false:
        ans = max(ans, len(ppl_truth))
print(ans)

-A = [[] for _ in range(N)] +A = [[set() for _ in range(2)] for _ in range(N)] -        A[i].append((x - 1, y)) - - -def countBit(x): -    if x == 0: -        return 0 -    else: -        return countBit(x >> 1) + (x & 1) - - -res = 0 -for bits in range(2**N): -    bits_ = bin(bits) -    consistency = True -    for i, testimony in enumerate(A): -        if not ((bits >> i) & 1): -            continue -        for t in testimony: -            if ((bits >> t[0]) & 1) ^ t[1]: -                consistency = False -    if consistency: -        res = max(res, countBit(bits)) -print(res) +        A[i][y].add(x - 1) +ans = 0 +for bit in range(1 << N): +    truth = set() +    false = set() +    ppl_truth = set() +    ppl_false = set() +    for i in range(N): +        if (bit >> i) & 1: +            ppl_truth.add(i) +            truth |= A[i][1] +            false |= A[i][0] +        else: +            ppl_false.add(i) +    if ppl_truth >= truth and ppl_false >= false: +        ans = max(ans, len(ppl_truth)) +print(ans)