n = int(eval(input()))



a_list = []

person_list = []

syogen_list = []

ans = 0



for i in range(0, n):

    w = []

    v = []

    a = int(eval(input()))

    for j in range(0, a):

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

        w.append(x)

        v.append(y)

    person_list.append(w)

    syogen_list.append(v)

#print(person_list)

#print(syogen_list)



for bit in range(1 << n):

    break_flag = 0

    bit_1_cnt = 0

    for i in range(n):

        if break_flag:

            break

        if (bit >> i) & 1: #人iが正直

            for j in range(len(syogen_list[i])):

                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1): #矛盾　：　正直としているのに証言が食い違えばbreak

                    break_flag = 1

                    break

            bit_1_cnt += 1

        if break_flag==0 and i==n-1:

            ans = max(ans, bit_1_cnt)

print(ans)

N = int(eval(input()))



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

for i in range(N):

    num = int(eval(input()))

    for j in range(num):

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

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



#print(syougen)

ans = 0

for bit in range(1 << N):

    break_flag = 0

    for i in range(N):

        if (bit >> i) & 1:

            for j in range(len(syougen[i])):

                if ((bit>>(syougen[i][j][0]-1))&1) != syougen[i][j][1]:

                    break_flag = 1

                    break

            if break_flag == 1:

                break

        if i == N-1:

            ans = max(ans, bin(bit).count("1"))

print(ans)
n = int(eval(input()))
a_list = []
person_list = []
syogen_list = []
ans = 0
for i in range(0, n):
    w = []
    v = []
    a = int(eval(input()))
    for j in range(0, a):
        x, y = list(map(int, input().split()))
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)
# print(person_list)
# print(syogen_list)
for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        if break_flag:
            break
        if (bit >> i) & 1:  # 人iが正直
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != (
                    (bit >> (person_list[i][j] - 1)) & 1
                ):  # 矛盾　：　正直としているのに証言が食い違えばbreak
                    break_flag = 1
                    break
            bit_1_cnt += 1
        if break_flag == 0 and i == n - 1:
            ans = max(ans, bit_1_cnt)
print(ans)

N = int(eval(input()))
syougen = [[] for _ in range(N)]
for i in range(N):
    num = int(eval(input()))
    for j in range(num):
        x, y = list(map(int, input().split()))
        syougen[i].append([x, y])
# print(syougen)
ans = 0
for bit in range(1 << N):
    break_flag = 0
    for i in range(N):
        if (bit >> i) & 1:
            for j in range(len(syougen[i])):
                if ((bit >> (syougen[i][j][0] - 1)) & 1) != syougen[i][j][1]:
                    break_flag = 1
                    break
            if break_flag == 1:
                break
        if i == N - 1:
            ans = max(ans, bin(bit).count("1"))
print(ans)

-n = int(eval(input())) -a_list = [] -person_list = [] -syogen_list = [] +N = int(eval(input())) +syougen = [[] for _ in range(N)] +for i in range(N): +    num = int(eval(input())) +    for j in range(num): +        x, y = list(map(int, input().split())) +        syougen[i].append([x, y]) +# print(syougen) -for i in range(0, n): -    w = [] -    v = [] -    a = int(eval(input())) -    for j in range(0, a): -        x, y = list(map(int, input().split())) -        w.append(x) -        v.append(y) -    person_list.append(w) -    syogen_list.append(v) -# print(person_list) -# print(syogen_list) -for bit in range(1 << n): +for bit in range(1 << N): -    bit_1_cnt = 0 -    for i in range(n): -        if break_flag: -            break -        if (bit >> i) & 1:  # 人iが正直 -            for j in range(len(syogen_list[i])): -                if syogen_list[i][j] != ( -                    (bit >> (person_list[i][j] - 1)) & 1 -                ):  # 矛盾　：　正直としているのに証言が食い違えばbreak +    for i in range(N): +        if (bit >> i) & 1: +            for j in range(len(syougen[i])): +                if ((bit >> (syougen[i][j][0] - 1)) & 1) != syougen[i][j][1]: -            bit_1_cnt += 1 -        if break_flag == 0 and i == n - 1: -            ans = max(ans, bit_1_cnt) +            if break_flag == 1: +                break +        if i == N - 1: +            ans = max(ans, bin(bit).count("1"))