def main():

    from itertools import product



    N = int(eval(input()))



    g = []

    for _ in range(N):

        a = int(eval(input()))

        t = []

        for _ in range(a):

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

            x -= 1

            t.append((x, y))

        g.append(t)



    def is_ok(prd):

        for j, bl in enumerate(prd):

            if bl:

                for x, y in g[j]:

                    if prd[x] != y:

                        return False

        return True



    ans = 0

    for prd in product([0, 1], repeat=N):

        *prd, = prd  # list化

        if is_ok(prd):

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

    print(ans)





if __name__ == '__main__':

    main()



# bit演算しようとしてはまった

def main():

    from itertools import product



    N = int(eval(input()))



    g = []

    for _ in range(N):

        a = int(eval(input()))

        t = []

        for _ in range(a):

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

            t.append((x - 1, y))

        g.append(t)



    def is_ok(prd):

        for j, bl in enumerate(prd):

            if bl:

                for x, y in g[j]:

                    if prd[x] != y:

                        return False

        return True



    ans = 0

    for prd in product([0, 1], repeat=N):

        if is_ok(prd):

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

    print(ans)





if __name__ == '__main__':

    main()



# bit演算しようとしてはまった

def main():
    from itertools import product

    N = int(eval(input()))
    g = []
    for _ in range(N):
        a = int(eval(input()))
        t = []
        for _ in range(a):
            x, y = list(map(int, input().split()))
            x -= 1
            t.append((x, y))
        g.append(t)

    def is_ok(prd):
        for j, bl in enumerate(prd):
            if bl:
                for x, y in g[j]:
                    if prd[x] != y:
                        return False
        return True

    ans = 0
    for prd in product([0, 1], repeat=N):
        (*prd,) = prd  # list化
        if is_ok(prd):
            ans = max(ans, prd.count(1))
    print(ans)


if __name__ == "__main__":
    main()
# bit演算しようとしてはまった

def main():
    from itertools import product

    N = int(eval(input()))
    g = []
    for _ in range(N):
        a = int(eval(input()))
        t = []
        for _ in range(a):
            x, y = list(map(int, input().split()))
            t.append((x - 1, y))
        g.append(t)

    def is_ok(prd):
        for j, bl in enumerate(prd):
            if bl:
                for x, y in g[j]:
                    if prd[x] != y:
                        return False
        return True

    ans = 0
    for prd in product([0, 1], repeat=N):
        if is_ok(prd):
            ans = max(ans, prd.count(1))
    print(ans)


if __name__ == "__main__":
    main()
# bit演算しようとしてはまった

-            x -= 1 -            t.append((x, y)) +            t.append((x - 1, y)) -        (*prd,) = prd  # list化