n = int(eval(input()))

shogens = []



for i in range(n):

    a = int(eval(input()))

    shogens.append([])

    for j in range(a):

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

        x -= 1

        shogens[-1].append((x,y))



def is_honest(i, j):

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



def honest_cnt(i):

    ans = 0

    for j in range(n):

        ans += is_honest(i, j)

    return ans



ans = 0



for i in range(1 << n):

    ok = True

    for j in range(n):

        if not is_honest(i,j):continue

        for (x, y) in shogens[j]:

            if y == 0 and is_honest(i, x):ok = False

            if y == 1 and not is_honest(i, x):ok = False

    if ok:

        ans = max(ans, honest_cnt(i))



print(ans)

        
n = int(eval(input()))

a = [0] * n

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

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



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 check(honest):

    for i in range(n):

        if not honest[i]:continue

        for j in range(a[i]):

            if y[i][j] == 1 and not honest[x[i][j]]:return False

            if y[i][j] == 0 and honest[x[i][j]]:return False

    return True

        

def dfs(honest):

    if len(honest) == n:

        if check(honest):

            return sum(honest)

        else:

            return 0

    return max(dfs(honest + [True]),

               dfs(honest + [False]))

    

print((dfs([])))

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


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


def honest_cnt(i):
    ans = 0
    for j in range(n):
        ans += is_honest(i, j)
    return ans


ans = 0
for i in range(1 << n):
    ok = True
    for j in range(n):
        if not is_honest(i, j):
            continue
        for (x, y) in shogens[j]:
            if y == 0 and is_honest(i, x):
                ok = False
            if y == 1 and not is_honest(i, x):
                ok = False
    if ok:
        ans = max(ans, honest_cnt(i))
print(ans)

n = int(eval(input()))
a = [0] * n
x = [[0] * n for i in range(n)]
y = [[0] * n for i in range(n)]
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 check(honest):
    for i in range(n):
        if not honest[i]:
            continue
        for j in range(a[i]):
            if y[i][j] == 1 and not honest[x[i][j]]:
                return False
            if y[i][j] == 0 and honest[x[i][j]]:
                return False
    return True


def dfs(honest):
    if len(honest) == n:
        if check(honest):
            return sum(honest)
        else:
            return 0
    return max(dfs(honest + [True]), dfs(honest + [False]))


print((dfs([])))

-shogens = [] +a = [0] * n +x = [[0] * n for i in range(n)] +y = [[0] * n for i in range(n)] -    a = int(eval(input())) -    shogens.append([]) -    for j in range(a): -        x, y = list(map(int, input().split())) -        x -= 1 -        shogens[-1].append((x, y)) +    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 is_honest(i, j): -    return (i >> j) % 2 == 1 +def check(honest): +    for i in range(n): +        if not honest[i]: +            continue +        for j in range(a[i]): +            if y[i][j] == 1 and not honest[x[i][j]]: +                return False +            if y[i][j] == 0 and honest[x[i][j]]: +                return False +    return True -def honest_cnt(i): -    ans = 0 -    for j in range(n): -        ans += is_honest(i, j) -    return ans +def dfs(honest): +    if len(honest) == n: +        if check(honest): +            return sum(honest) +        else: +            return 0 +    return max(dfs(honest + [True]), dfs(honest + [False])) -ans = 0 -for i in range(1 << n): -    ok = True -    for j in range(n): -        if not is_honest(i, j): -            continue -        for (x, y) in shogens[j]: -            if y == 0 and is_honest(i, x): -                ok = False -            if y == 1 and not is_honest(i, x): -                ok = False -    if ok: -        ans = max(ans, honest_cnt(i)) -print(ans) +print((dfs([])))