n = int(eval(input()))



a = []

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



for i in range(n):

    

    k = int(eval(input()))

    a.append(k)

    

    for j in range(k):

        x[i].append(list(map(int,input().split())))



# print(x)

ans = 0

for i in range(1<<n):

    

    cnt = bin(i).count("1")

    if ans > cnt:

        continue

    flag = True

    for j in range(n):

        # if i==3:

        #     print(i,j,i>>j&1,cnt)

        if i>>j & 1:

            # True if 1

            # if i==3:

                # print(i,j)

            for t in x[j]:

                # 証言:testimony

                # if i == 3:

                    # print(i,t[0]-1, i>>t[0]-1, t[1])

                if (i>>(t[0]-1) &1 ) != t[1]:

                    flag = False

                        # break

            # if flag == False:

            #     break

    # if flag == False:

    #     break

    if flag == True:

        # print(i) # 0 000

        ans = cnt



print(ans)

n = int(eval(input()))



a = []

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



for i in range(n):

    

    k = int(eval(input()))

    a.append(k)

    

    for j in range(k):

        x[i].append(list(map(int,input().split())))



# print(x)

ans = 0

for i in range(1<<n):

    

    cnt = bin(i).count("1")

    if ans > cnt:

        continue

    flag = True

    for j in range(n):

        # if i==3:

        #     print(i,j,i>>j&1,cnt)

        if i>>j & 1:

            # True if 1

            # if i==3:

                # print(i,j)

            for t in x[j]:

                # 証言:testimony

                # if i == 3:

                    # print(i,t[0]-1, i>>t[0]-1, t[1])

                if (i>>(t[0]-1) &1 ) != t[1]:

                    flag = False

                    break

    # if flag == False:

    #     break

    if flag == True:

        # print(i) # 0 000

        ans = cnt



print(ans)

n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
    k = int(eval(input()))
    a.append(k)
    for j in range(k):
        x[i].append(list(map(int, input().split())))
# print(x)
ans = 0
for i in range(1 << n):
    cnt = bin(i).count("1")
    if ans > cnt:
        continue
    flag = True
    for j in range(n):
        # if i==3:
        #     print(i,j,i>>j&1,cnt)
        if i >> j & 1:
            # True if 1
            # if i==3:
            # print(i,j)
            for t in x[j]:
                # 証言:testimony
                # if i == 3:
                # print(i,t[0]-1, i>>t[0]-1, t[1])
                if (i >> (t[0] - 1) & 1) != t[1]:
                    flag = False
                    # break
            # if flag == False:
            #     break
    # if flag == False:
    #     break
    if flag == True:
        # print(i) # 0 000
        ans = cnt
print(ans)

n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
    k = int(eval(input()))
    a.append(k)
    for j in range(k):
        x[i].append(list(map(int, input().split())))
# print(x)
ans = 0
for i in range(1 << n):
    cnt = bin(i).count("1")
    if ans > cnt:
        continue
    flag = True
    for j in range(n):
        # if i==3:
        #     print(i,j,i>>j&1,cnt)
        if i >> j & 1:
            # True if 1
            # if i==3:
            # print(i,j)
            for t in x[j]:
                # 証言:testimony
                # if i == 3:
                # print(i,t[0]-1, i>>t[0]-1, t[1])
                if (i >> (t[0] - 1) & 1) != t[1]:
                    flag = False
                    break
    # if flag == False:
    #     break
    if flag == True:
        # print(i) # 0 000
        ans = cnt
print(ans)

-                    # break -            # if flag == False: -            #     break +                    break