import sys



stdin = sys.stdin

 

ri = lambda: int(rs())

rl = lambda: list(map(int, stdin.readline().split()))

rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces



N = ri()

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

for i in range(N):

    a = ri()

    l = []

    for j in range(a):

        x, y = rl()

        l.append((x, y))

    A[i] = l



answer = 0



for i in range(2 ** N):

    honest = [False] * (N+1)

    bool = True

    for j in range(N):

        if ((i >> j) & 1):

            honest[N - j] = True

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

        if honest[k] == True:

            #k番目の人は正直者

            for x, y in A[k-1]:

                if y == 1 and honest[x] == False:

                    bool = False

                    break

                if y == 0 and honest[x] == True:

                    bool = False

                    break

    if bool and sum(honest) > answer:

        answer = max(answer, sum(honest))



print(answer)

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



answer = 0

N = ir()

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

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

# bit全探索

for i in range(N):

    a = ir()

    for _ in range(a):

        x, y = lr()

        if y == 1:

            honest[i].append(x-1)

        else:

            liar[i].append(x-1)



for bit in range(1<<N):

    bl = True

    h = []

    for i in range(N):

        if (bit >> i) & 1:

            h.append(i)

    s = set(h)

    for person in h:

        for x in honest[person]:

            if x not in s:

                bl = False

                break

        for y in liar[person]:

            if y in s:

                bl = False

                break

        if not bl:

            break

    if bl:

        answer = max(answer, len(s))



print(answer)

import sys

stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
N = ri()
A = [[] for _ in range(N)]
for i in range(N):
    a = ri()
    l = []
    for j in range(a):
        x, y = rl()
        l.append((x, y))
    A[i] = l
answer = 0
for i in range(2**N):
    honest = [False] * (N + 1)
    bool = True
    for j in range(N):
        if (i >> j) & 1:
            honest[N - j] = True
    for k in range(1, N + 1):
        if honest[k] == True:
            # k番目の人は正直者
            for x, y in A[k - 1]:
                if y == 1 and honest[x] == False:
                    bool = False
                    break
                if y == 0 and honest[x] == True:
                    bool = False
                    break
    if bool and sum(honest) > answer:
        answer = max(answer, sum(honest))
print(answer)

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
answer = 0
N = ir()
honest = [[] for _ in range(N + 1)]
liar = [[] for _ in range(N + 1)]
# bit全探索
for i in range(N):
    a = ir()
    for _ in range(a):
        x, y = lr()
        if y == 1:
            honest[i].append(x - 1)
        else:
            liar[i].append(x - 1)
for bit in range(1 << N):
    bl = True
    h = []
    for i in range(N):
        if (bit >> i) & 1:
            h.append(i)
    s = set(h)
    for person in h:
        for x in honest[person]:
            if x not in s:
                bl = False
                break
        for y in liar[person]:
            if y in s:
                bl = False
                break
        if not bl:
            break
    if bl:
        answer = max(answer, len(s))
print(answer)

-stdin = sys.stdin -ri = lambda: int(rs()) -rl = lambda: list(map(int, stdin.readline().split())) -rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces -N = ri() -A = [[] for _ in range(N)] +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +answer = 0 +N = ir() +honest = [[] for _ in range(N + 1)] +liar = [[] for _ in range(N + 1)] +# bit全探索 -    a = ri() -    l = [] -    for j in range(a): -        x, y = rl() -        l.append((x, y)) -    A[i] = l -answer = 0 -for i in range(2**N): -    honest = [False] * (N + 1) -    bool = True -    for j in range(N): -        if (i >> j) & 1: -            honest[N - j] = True -    for k in range(1, N + 1): -        if honest[k] == True: -            # k番目の人は正直者 -            for x, y in A[k - 1]: -                if y == 1 and honest[x] == False: -                    bool = False -                    break -                if y == 0 and honest[x] == True: -                    bool = False -                    break -    if bool and sum(honest) > answer: -        answer = max(answer, sum(honest)) +    a = ir() +    for _ in range(a): +        x, y = lr() +        if y == 1: +            honest[i].append(x - 1) +        else: +            liar[i].append(x - 1) +for bit in range(1 << N): +    bl = True +    h = [] +    for i in range(N): +        if (bit >> i) & 1: +            h.append(i) +    s = set(h) +    for person in h: +        for x in honest[person]: +            if x not in s: +                bl = False +                break +        for y in liar[person]: +            if y in s: +                bl = False +                break +        if not bl: +            break +    if bl: +        answer = max(answer, len(s))