n = int(eval(input()))

a = [0]*n

x = [[0] *n for i in range(n)]

y = [[0] *n for i in range(n)]

ans = 0

for i in range(n):

    a[i] = int(eval(input()))

    for j in range(a[i]):

        x[i][j],y[i][j] = list(map(int,input().split()))

        x[i][j]-=1

def honest(i,j):

    return (i>>j)%2 ==1

def check(m):

    for i in range(n):

        if not honest(m,i) :continue

        for j in range(a[i]):

            if y[i][j] == 1 and honest(m,x[i][j]) == 0:

                return False

            if y[i][j] == 0 and honest(m,x[i][j]) == 1:

                return False

    return True

def count(c):

    cnt = 0

    for i in range(c//2+5):

        cnt+= (c >> i)%2

    return cnt

for i in range(2**n):

    if check(i):

        ans = max(ans,count(i))

    

        

        

        

print(ans)

        

import sys

sys.setrecursionlimit(10**7)

n = int(eval(input()))

people = []

shogens = [[]for i in range(n)]

def check():

    for i in range(n):

        if i not in people:continue

        for shogen in shogens[i]:

            person = shogen[0]

            honest = shogen[1]

            if honest and person not in people:return False

            if (not honest) and person in people:return False

    return True

        

            

            

            

        

for i in range(n):

    a = int(eval(input()))

    for j in range(a):

        p,q = list(map(int,input().split()))

        p -= 1

        shogens[i].append((p,q))

def dfs(d,people):

    if d == n:

        

        if check():

            

            return len(people)

        else:

            return 0

    res = dfs(d+1,people)

    people.append(d)

    res = max(res,dfs(d+1,people))

    people.pop()

    return res

print((dfs(0,people)))

n = int(eval(input()))
a = [0] * n
x = [[0] * n for i in range(n)]
y = [[0] * n for i in range(n)]
ans = 0
for i in range(n):
    a[i] = int(eval(input()))
    for j in range(a[i]):
        x[i][j], y[i][j] = list(map(int, input().split()))
        x[i][j] -= 1


def honest(i, j):
    return (i >> j) % 2 == 1


def check(m):
    for i in range(n):
        if not honest(m, i):
            continue
        for j in range(a[i]):
            if y[i][j] == 1 and honest(m, x[i][j]) == 0:
                return False
            if y[i][j] == 0 and honest(m, x[i][j]) == 1:
                return False
    return True


def count(c):
    cnt = 0
    for i in range(c // 2 + 5):
        cnt += (c >> i) % 2
    return cnt


for i in range(2**n):
    if check(i):
        ans = max(ans, count(i))
print(ans)

import sys

sys.setrecursionlimit(10**7)
n = int(eval(input()))
people = []
shogens = [[] for i in range(n)]


def check():
    for i in range(n):
        if i not in people:
            continue
        for shogen in shogens[i]:
            person = shogen[0]
            honest = shogen[1]
            if honest and person not in people:
                return False
            if (not honest) and person in people:
                return False
    return True


for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        p, q = list(map(int, input().split()))
        p -= 1
        shogens[i].append((p, q))


def dfs(d, people):
    if d == n:
        if check():
            return len(people)
        else:
            return 0
    res = dfs(d + 1, people)
    people.append(d)
    res = max(res, dfs(d + 1, people))
    people.pop()
    return res


print((dfs(0, people)))

+import sys + +sys.setrecursionlimit(10**7) -a = [0] * n -x = [[0] * n for i in range(n)] -y = [[0] * n for i in range(n)] -ans = 0 -for i in range(n): -    a[i] = int(eval(input())) -    for j in range(a[i]): -        x[i][j], y[i][j] = list(map(int, input().split())) -        x[i][j] -= 1 +people = [] +shogens = [[] for i in range(n)] -def honest(i, j): -    return (i >> j) % 2 == 1 - - -def check(m): +def check(): -        if not honest(m, i): +        if i not in people: -        for j in range(a[i]): -            if y[i][j] == 1 and honest(m, x[i][j]) == 0: +        for shogen in shogens[i]: +            person = shogen[0] +            honest = shogen[1] +            if honest and person not in people: -            if y[i][j] == 0 and honest(m, x[i][j]) == 1: +            if (not honest) and person in people: -def count(c): -    cnt = 0 -    for i in range(c // 2 + 5): -        cnt += (c >> i) % 2 -    return cnt +for i in range(n): +    a = int(eval(input())) +    for j in range(a): +        p, q = list(map(int, input().split())) +        p -= 1 +        shogens[i].append((p, q)) -for i in range(2**n): -    if check(i): -        ans = max(ans, count(i)) -print(ans) +def dfs(d, people): +    if d == n: +        if check(): +            return len(people) +        else: +            return 0 +    res = dfs(d + 1, people) +    people.append(d) +    res = max(res, dfs(d + 1, people)) +    people.pop() +    return res + + +print((dfs(0, people)))