def resolve():

    N = int(eval(input()))

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

            L[i].append((x, y))



    ans = 0

    for p in range(1, 2**N):

        isOk = True

        for i in range(N):

            for x, y in L[i]:

                if p & (1 << i):

                    if p & 1 << (x-1) and not y:

                        isOk = False

                        break

                    elif not(p & 1 << (x-1)) and y:

                        isOk = False

                        break



                if not isOk:

                    break



        if isOk:

            ans = max(ans, bin(p).count('1'))



    print(ans)



if __name__ == '__main__':

    resolve()

def resolve():

    N = int(eval(input()))

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

            L[i].append((x, y))



    ans = 0

    for p in range(2**N):

        ok = True

        for i in range(N):

            for x, y in L[i]:

                if p & (1 << i):

                    if p & (1 << (x-1)) > 0 and y == 0:

                        ok = False

                        break

                    elif p & (1 << (x-1)) == 0 and y == 1:

                        ok = False

                        break



            if not ok:

                break



        if ok:

            ans = max(ans, bin(p).count('1'))



    print(ans)



if __name__ == '__main__':

    resolve()

def resolve():
    N = int(eval(input()))
    L = [[] 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()))
            L[i].append((x, y))
    ans = 0
    for p in range(1, 2**N):
        isOk = True
        for i in range(N):
            for x, y in L[i]:
                if p & (1 << i):
                    if p & 1 << (x - 1) and not y:
                        isOk = False
                        break
                    elif not (p & 1 << (x - 1)) and y:
                        isOk = False
                        break
                if not isOk:
                    break
        if isOk:
            ans = max(ans, bin(p).count("1"))
    print(ans)


if __name__ == "__main__":
    resolve()

def resolve():
    N = int(eval(input()))
    L = [[] 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()))
            L[i].append((x, y))
    ans = 0
    for p in range(2**N):
        ok = True
        for i in range(N):
            for x, y in L[i]:
                if p & (1 << i):
                    if p & (1 << (x - 1)) > 0 and y == 0:
                        ok = False
                        break
                    elif p & (1 << (x - 1)) == 0 and y == 1:
                        ok = False
                        break
            if not ok:
                break
        if ok:
            ans = max(ans, bin(p).count("1"))
    print(ans)


if __name__ == "__main__":
    resolve()

-    for p in range(1, 2**N): -        isOk = True +    for p in range(2**N): +        ok = True -                    if p & 1 << (x - 1) and not y: -                        isOk = False +                    if p & (1 << (x - 1)) > 0 and y == 0: +                        ok = False -                    elif not (p & 1 << (x - 1)) and y: -                        isOk = False +                    elif p & (1 << (x - 1)) == 0 and y == 1: +                        ok = False -                if not isOk: -                    break -        if isOk: +            if not ok: +                break +        if ok: