from itertools import combinations

import sys



N = int(eval(input()))

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

B = [[] for _ in range(N + 1)]

C = [[] for _ in range(N + 1)]

num_hint = []

# hint_dict = {}

for i in range(1, N + 1):

    num_i = int(eval(input()))

    num_hint.append(num_i)

    for j in range(num_i):

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

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

        if y == 1:

            B[i].append(x)

        if y == 0:

            C[i].append(x)

        # if hint_dict.get(x) is None:

        #     hint_dict[x] = {0: [], 1: []}

        #     hint_dict[x][y].append(i)

        # else:

        #     hint_dict[x][y].append(i)



for i in range(N + 1, 0, -1):

    for combi in combinations(list(range(1, N + 1)), i):

        remain = set(range(1, N + 1)) - set(combi)

        s = set()

        t = set()

        hint_dict = {}

        for j in combi:

            s |= set(B[j])

            t |= set(C[j])

            for x, y in A[j]:

                if hint_dict.get(x) is None:

                    hint_dict[x] = {0: [], 1: []}

                    hint_dict[x][y].append(i)

                else:

                    hint_dict[x][y].append(i)

        good1 = True

        for value in list(hint_dict.values()):

            if len(value[0]) != 0 and len(value[1]) != 0:

                good1 = False

                break

        good2 = True

        if len(s & remain) != 0:

            good2 = False

        good3 = True

        if len(t & set(combi)) != 0:

            good3 = False

        if good1 and good2 and good3:

            print(i)

            sys.exit()

print((0))

N = int(eval(input()))



XY = []

for _ in range(N):

    A = int(eval(input()))

    tmp = []

    for _ in range(A):

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

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

    XY.append(tmp)





def judge(bit):

    for i in range(N):

        if not (bit & (1 << i)):

            continue

        for x, y in XY[i]:

            if y == 1 and (not (bit & (1 << x))):

                return False

            if y == 0 and (bit & (1 << x)):

                return False

    return True





ans = 0

for bit in range(1 << N):

    if (judge(bit)):

        # print('bit', bit, bin(bit))

        cnt = 0

        for i in range(N):

            if (bit & (1 << i)):

                cnt += 1

        ans = max(ans, cnt)

print(ans)

from itertools import combinations
import sys

N = int(eval(input()))
A = [[] for _ in range(N + 1)]
B = [[] for _ in range(N + 1)]
C = [[] for _ in range(N + 1)]
num_hint = []
# hint_dict = {}
for i in range(1, N + 1):
    num_i = int(eval(input()))
    num_hint.append(num_i)
    for j in range(num_i):
        x, y = list(map(int, input().split()))
        A[i].append((x, y))
        if y == 1:
            B[i].append(x)
        if y == 0:
            C[i].append(x)
        # if hint_dict.get(x) is None:
        #     hint_dict[x] = {0: [], 1: []}
        #     hint_dict[x][y].append(i)
        # else:
        #     hint_dict[x][y].append(i)
for i in range(N + 1, 0, -1):
    for combi in combinations(list(range(1, N + 1)), i):
        remain = set(range(1, N + 1)) - set(combi)
        s = set()
        t = set()
        hint_dict = {}
        for j in combi:
            s |= set(B[j])
            t |= set(C[j])
            for x, y in A[j]:
                if hint_dict.get(x) is None:
                    hint_dict[x] = {0: [], 1: []}
                    hint_dict[x][y].append(i)
                else:
                    hint_dict[x][y].append(i)
        good1 = True
        for value in list(hint_dict.values()):
            if len(value[0]) != 0 and len(value[1]) != 0:
                good1 = False
                break
        good2 = True
        if len(s & remain) != 0:
            good2 = False
        good3 = True
        if len(t & set(combi)) != 0:
            good3 = False
        if good1 and good2 and good3:
            print(i)
            sys.exit()
print((0))

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


def judge(bit):
    for i in range(N):
        if not (bit & (1 << i)):
            continue
        for x, y in XY[i]:
            if y == 1 and (not (bit & (1 << x))):
                return False
            if y == 0 and (bit & (1 << x)):
                return False
    return True


ans = 0
for bit in range(1 << N):
    if judge(bit):
        # print('bit', bit, bin(bit))
        cnt = 0
        for i in range(N):
            if bit & (1 << i):
                cnt += 1
        ans = max(ans, cnt)
print(ans)

-from itertools import combinations -import sys +N = int(eval(input())) +XY = [] +for _ in range(N): +    A = int(eval(input())) +    tmp = [] +    for _ in range(A): +        x, y = list(map(int, input().split())) +        tmp.append((x - 1, y)) +    XY.append(tmp) -N = int(eval(input())) -A = [[] for _ in range(N + 1)] -B = [[] for _ in range(N + 1)] -C = [[] for _ in range(N + 1)] -num_hint = [] -# hint_dict = {} -for i in range(1, N + 1): -    num_i = int(eval(input())) -    num_hint.append(num_i) -    for j in range(num_i): -        x, y = list(map(int, input().split())) -        A[i].append((x, y)) -        if y == 1: -            B[i].append(x) -        if y == 0: -            C[i].append(x) -        # if hint_dict.get(x) is None: -        #     hint_dict[x] = {0: [], 1: []} -        #     hint_dict[x][y].append(i) -        # else: -        #     hint_dict[x][y].append(i) -for i in range(N + 1, 0, -1): -    for combi in combinations(list(range(1, N + 1)), i): -        remain = set(range(1, N + 1)) - set(combi) -        s = set() -        t = set() -        hint_dict = {} -        for j in combi: -            s |= set(B[j]) -            t |= set(C[j]) -            for x, y in A[j]: -                if hint_dict.get(x) is None: -                    hint_dict[x] = {0: [], 1: []} -                    hint_dict[x][y].append(i) -                else: -                    hint_dict[x][y].append(i) -        good1 = True -        for value in list(hint_dict.values()): -            if len(value[0]) != 0 and len(value[1]) != 0: -                good1 = False -                break -        good2 = True -        if len(s & remain) != 0: -            good2 = False -        good3 = True -        if len(t & set(combi)) != 0: -            good3 = False -        if good1 and good2 and good3: -            print(i) -            sys.exit() -print((0)) + +def judge(bit): +    for i in range(N): +        if not (bit & (1 << i)): +            continue +        for x, y in XY[i]: +            if y == 1 and (not (bit & (1 << x))): +                return False +            if y == 0 and (bit & (1 << x)): +                return False +    return True + + +ans = 0 +for bit in range(1 << N): +    if judge(bit): +        # print('bit', bit, bin(bit)) +        cnt = 0 +        for i in range(N): +            if bit & (1 << i): +                cnt += 1 +        ans = max(ans, cnt) +print(ans)