N = int(eval(input()))

xs = [[] for i in range(N)]

for i in range(N):

    a = int(eval(input()))

    for j in range(a):

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

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

ans = 0

for b in range(1<<N):

    mujun = False

    for k,z in enumerate(xs):

        for x,y in z:

            if b&(1<<k):

                if b&(1<<x):

                    if y==0:

                        mujun = True

                else:

                    if y==1:

                        mujun = True

            if mujun:

                break

        if mujun:

            break

    if not mujun:

        tmp = bin(b).count('1')

        ans = max(ans, tmp)

print(ans)
N = int(eval(input()))

xys = [[] 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()))

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



ans = 0

for b in range(1<<N):

    cnt = bin(b).count('1')

    if cnt <= ans: continue

    for i in range(N):

        if b&(1<<i):

            for x,y in xys[i]:

                if y==1 and b&(1<<x): continue

                if y==0 and b&(1<<x)==0: continue

                break

            else:

                continue

            break

    else:

        ans = cnt

print(ans)
N = int(eval(input()))
xs = [[] for i in range(N)]
for i in range(N):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        xs[i].append((x - 1, y))
ans = 0
for b in range(1 << N):
    mujun = False
    for k, z in enumerate(xs):
        for x, y in z:
            if b & (1 << k):
                if b & (1 << x):
                    if y == 0:
                        mujun = True
                else:
                    if y == 1:
                        mujun = True
            if mujun:
                break
        if mujun:
            break
    if not mujun:
        tmp = bin(b).count("1")
        ans = max(ans, tmp)
print(ans)

N = int(eval(input()))
xys = [[] 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()))
        xys[i].append((x - 1, y))
ans = 0
for b in range(1 << N):
    cnt = bin(b).count("1")
    if cnt <= ans:
        continue
    for i in range(N):
        if b & (1 << i):
            for x, y in xys[i]:
                if y == 1 and b & (1 << x):
                    continue
                if y == 0 and b & (1 << x) == 0:
                    continue
                break
            else:
                continue
            break
    else:
        ans = cnt
print(ans)

-xs = [[] for i in range(N)] +xys = [[] for _ in range(N)] -    a = int(eval(input())) -    for j in range(a): +    A = int(eval(input())) +    for j in range(A): -        xs[i].append((x - 1, y)) +        xys[i].append((x - 1, y)) -    mujun = False -    for k, z in enumerate(xs): -        for x, y in z: -            if b & (1 << k): -                if b & (1 << x): -                    if y == 0: -                        mujun = True -                else: -                    if y == 1: -                        mujun = True -            if mujun: +    cnt = bin(b).count("1") +    if cnt <= ans: +        continue +    for i in range(N): +        if b & (1 << i): +            for x, y in xys[i]: +                if y == 1 and b & (1 << x): +                    continue +                if y == 0 and b & (1 << x) == 0: +                    continue -        if mujun: +            else: +                continue -    if not mujun: -        tmp = bin(b).count("1") -        ans = max(ans, tmp) +    else: +        ans = cnt