from collections import defaultdict,deque

n = int(eval(input()))

d = defaultdict(list)

for i in range(n):

    a = int(eval(input()))

    for j in range(a):

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

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

        

maxi = 0

for i in range(2 ** n):

    honest = [-1]*n

    que = deque([])

    for j in range(n):

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

            que.append(n-1-j)

            honest[n-1-j] = True

    flag = True

    while que and flag:

        v = que.popleft()

        for x,y in d[v]:

            if honest[x] == -1:

                honest[x] = y

                if y:

                    que.append(x)

            elif honest[x] != y:

                flag = False

                break

    if flag:

        maxi = max(maxi,str(bin(i)).count('1'))

print(maxi)
def judge(bit):

    global l

    for i in range(n):

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

            continue

        for x,y in l[i]:

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

                return False

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

                return False

    return True



n = int(eval(input()))

l = [[] for _ in range(n)]

for i in range(n):

    a = int(eval(input()))

    for j in range(a):

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

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

maxi = 0

for bit in range(2**n):

    if judge(bit):

        maxi = max(maxi,str(bin(bit)).count('1'))

print(maxi)
from collections import defaultdict, deque

n = int(eval(input()))
d = defaultdict(list)
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        d[i].append((x - 1, bool(y)))
maxi = 0
for i in range(2**n):
    honest = [-1] * n
    que = deque([])
    for j in range(n):
        if (i >> j) & 1:
            que.append(n - 1 - j)
            honest[n - 1 - j] = True
    flag = True
    while que and flag:
        v = que.popleft()
        for x, y in d[v]:
            if honest[x] == -1:
                honest[x] = y
                if y:
                    que.append(x)
            elif honest[x] != y:
                flag = False
                break
    if flag:
        maxi = max(maxi, str(bin(i)).count("1"))
print(maxi)

def judge(bit):
    global l
    for i in range(n):
        if (bit >> i) & 1 == 0:
            continue
        for x, y in l[i]:
            if y == 1 and (bit >> x) & 1 == 0:
                return False
            if y == 0 and (bit >> x) & 1 == 1:
                return False
    return True


n = int(eval(input()))
l = [[] for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        l[i].append((x - 1, y))
maxi = 0
for bit in range(2**n):
    if judge(bit):
        maxi = max(maxi, str(bin(bit)).count("1"))
print(maxi)

-from collections import defaultdict, deque +def judge(bit): +    global l +    for i in range(n): +        if (bit >> i) & 1 == 0: +            continue +        for x, y in l[i]: +            if y == 1 and (bit >> x) & 1 == 0: +                return False +            if y == 0 and (bit >> x) & 1 == 1: +                return False +    return True + -d = defaultdict(list) +l = [[] for _ in range(n)] -        d[i].append((x - 1, bool(y))) +        l[i].append((x - 1, y)) -for i in range(2**n): -    honest = [-1] * n -    que = deque([]) -    for j in range(n): -        if (i >> j) & 1: -            que.append(n - 1 - j) -            honest[n - 1 - j] = True -    flag = True -    while que and flag: -        v = que.popleft() -        for x, y in d[v]: -            if honest[x] == -1: -                honest[x] = y -                if y: -                    que.append(x) -            elif honest[x] != y: -                flag = False -                break -    if flag: -        maxi = max(maxi, str(bin(i)).count("1")) +for bit in range(2**n): +    if judge(bit): +        maxi = max(maxi, str(bin(bit)).count("1"))