#python3 

g=[[-1 for _ in range(15)] for _ in range(15)]

n=int(eval(input()))

for i in range(n):

  a=int(eval(input()))

  for _ in range(a):

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

    g[i][x-1]=y



ans=0

for i in range(1<<n):

  hy = [0 for _ in range(n)]

  for j in range(n):

    if (i>>j)&1:

      hy[j]=1



  ok = True 

  for j in range(n):

    if hy[j]==1:

      for k in range(n):

        if g[j][k] == -1: continue; 

        if g[j][k] != hy[k]: ok = False; 

  if ok:

    ans=max(ans, hy.count(1))



print(ans)
#python3



graph = [[-1 for _ in range(15)] for _ in range(15)]



def main():

    n = int(eval(input()))

    for i in range(n):

        a = int(eval(input()))

        for j in range(a):

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

            graph[i][x-1] = y

            

    ans = 0

    for i in range(1<<15):

        h = [0]*15

        for k in range(n):

            if (i >> k) & 1:

                h[k] = 1



        f = True

        for i in range(15):

            if h[i] == 1:

                for j in range(n):

                    if graph[i][j] == -1:

                        continue

                    if graph[i][j] != h[j]:

                        f = False



        if f:

            ans = max(ans, sum(h))



    print(ans)

main()
# python3
g = [[-1 for _ in range(15)] for _ in range(15)]
n = int(eval(input()))
for i in range(n):
    a = int(eval(input()))
    for _ in range(a):
        x, y = list(map(int, input().split()))
        g[i][x - 1] = y
ans = 0
for i in range(1 << n):
    hy = [0 for _ in range(n)]
    for j in range(n):
        if (i >> j) & 1:
            hy[j] = 1
    ok = True
    for j in range(n):
        if hy[j] == 1:
            for k in range(n):
                if g[j][k] == -1:
                    continue
                if g[j][k] != hy[k]:
                    ok = False
    if ok:
        ans = max(ans, hy.count(1))
print(ans)

# python3
graph = [[-1 for _ in range(15)] for _ in range(15)]


def main():
    n = int(eval(input()))
    for i in range(n):
        a = int(eval(input()))
        for j in range(a):
            x, y = list(map(int, input().split()))
            graph[i][x - 1] = y
    ans = 0
    for i in range(1 << 15):
        h = [0] * 15
        for k in range(n):
            if (i >> k) & 1:
                h[k] = 1
        f = True
        for i in range(15):
            if h[i] == 1:
                for j in range(n):
                    if graph[i][j] == -1:
                        continue
                    if graph[i][j] != h[j]:
                        f = False
        if f:
            ans = max(ans, sum(h))
    print(ans)


main()

-g = [[-1 for _ in range(15)] for _ in range(15)] -n = int(eval(input())) -for i in range(n): -    a = int(eval(input())) -    for _ in range(a): -        x, y = list(map(int, input().split())) -        g[i][x - 1] = y -ans = 0 -for i in range(1 << n): -    hy = [0 for _ in range(n)] -    for j in range(n): -        if (i >> j) & 1: -            hy[j] = 1 -    ok = True -    for j in range(n): -        if hy[j] == 1: -            for k in range(n): -                if g[j][k] == -1: -                    continue -                if g[j][k] != hy[k]: -                    ok = False -    if ok: -        ans = max(ans, hy.count(1)) -print(ans) +graph = [[-1 for _ in range(15)] for _ in range(15)] + + +def main(): +    n = int(eval(input())) +    for i in range(n): +        a = int(eval(input())) +        for j in range(a): +            x, y = list(map(int, input().split())) +            graph[i][x - 1] = y +    ans = 0 +    for i in range(1 << 15): +        h = [0] * 15 +        for k in range(n): +            if (i >> k) & 1: +                h[k] = 1 +        f = True +        for i in range(15): +            if h[i] == 1: +                for j in range(n): +                    if graph[i][j] == -1: +                        continue +                    if graph[i][j] != h[j]: +                        f = False +        if f: +            ans = max(ans, sum(h)) +    print(ans) + + +main()