def int_to_list(bit, n):

    l = []

    for i in range(n):

     if bit & (1 << i):

         l.append(i)

    return l



def solve():

    N = int(eval(input()))

    

    l = [[] for _ in range(N)]

    for i in range(N):

        for _ in range(int(eval(input()))):

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

            l[i].append((p-1, q))



    ans = 0

    for i in range(1 << N):

        partial = int_to_list(i, N)



        f = True

        for j in range(N):

            if j not in partial: continue

            for p, q in l[j]:

                if q == 0 and p in partial:

                    f = False

                if q == 1 and not p in partial:

                    f = False

        if f:

            ans = max(ans, len(partial))

            

    return ans



print((solve()))
def int_to_list(bit, n):

    l = []

    for i in range(n):

     if bit & (1 << i):

         l.append(i)

    return l



def solve():

    N = int(eval(input()))

    A = [[] for _ in range(N)]

    for i in range(N):

        B = int(eval(input()))

        for _ in range(B):

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

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



    ans = 0

    for i in range(1 << N):

        f = True

        # 正直者のリスト

        partial = int_to_list(i, N)

        for p in partial:

            for (a, b) in A[p]:

                if b == 1:

                    if not a in partial:

                        f = False

                else:

                    if a in partial:

                        f = False

        if f:

            ans = max(ans, len(partial))



    return ans



print((solve()))
def int_to_list(bit, n):
    l = []
    for i in range(n):
        if bit & (1 << i):
            l.append(i)
    return l


def solve():
    N = int(eval(input()))
    l = [[] for _ in range(N)]
    for i in range(N):
        for _ in range(int(eval(input()))):
            p, q = list(map(int, input().split()))
            l[i].append((p - 1, q))
    ans = 0
    for i in range(1 << N):
        partial = int_to_list(i, N)
        f = True
        for j in range(N):
            if j not in partial:
                continue
            for p, q in l[j]:
                if q == 0 and p in partial:
                    f = False
                if q == 1 and not p in partial:
                    f = False
        if f:
            ans = max(ans, len(partial))
    return ans


print((solve()))

def int_to_list(bit, n):
    l = []
    for i in range(n):
        if bit & (1 << i):
            l.append(i)
    return l


def solve():
    N = int(eval(input()))
    A = [[] for _ in range(N)]
    for i in range(N):
        B = int(eval(input()))
        for _ in range(B):
            x, y = list(map(int, input().split()))
            A[i].append((x - 1, y))
    ans = 0
    for i in range(1 << N):
        f = True
        # 正直者のリスト
        partial = int_to_list(i, N)
        for p in partial:
            for (a, b) in A[p]:
                if b == 1:
                    if not a in partial:
                        f = False
                else:
                    if a in partial:
                        f = False
        if f:
            ans = max(ans, len(partial))
    return ans


print((solve()))

-    l = [[] for _ in range(N)] +    A = [[] for _ in range(N)] -        for _ in range(int(eval(input()))): -            p, q = list(map(int, input().split())) -            l[i].append((p - 1, q)) +        B = int(eval(input())) +        for _ in range(B): +            x, y = list(map(int, input().split())) +            A[i].append((x - 1, y)) +        f = True +        # 正直者のリスト -        f = True -        for j in range(N): -            if j not in partial: -                continue -            for p, q in l[j]: -                if q == 0 and p in partial: -                    f = False -                if q == 1 and not p in partial: -                    f = False +        for p in partial: +            for (a, b) in A[p]: +                if b == 1: +                    if not a in partial: +                        f = False +                else: +                    if a in partial: +                        f = False