n = int(eval(input()))



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



for i in range(n):

    a = int(eval(input()))

    for _ in range(a):

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

        x -= 1

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



ret = 0

for mask in range(1 << n):

    t = [(mask >> i) & 1 for i in range(n)]

    flg = True

    for i in range(n):

        if t[i]:

            for x, y in e[i]:

                if t[x] != y:

                    flg = False

                    break

            if not flg:

                break

    if flg:

        ret = max(ret, sum(t))



print(ret)
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演算しようとしてはまった

n = int(eval(input()))
e = [[] for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for _ in range(a):
        x, y = list(map(int, input().split()))
        x -= 1
        e[i].append((x, y))
ret = 0
for mask in range(1 << n):
    t = [(mask >> i) & 1 for i in range(n)]
    flg = True
    for i in range(n):
        if t[i]:
            for x, y in e[i]:
                if t[x] != y:
                    flg = False
                    break
            if not flg:
                break
    if flg:
        ret = max(ret, sum(t))
print(ret)

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演算しようとしてはまった

-n = int(eval(input())) -e = [[] for _ in range(n)] -for i in range(n): -    a = int(eval(input())) -    for _ in range(a): -        x, y = list(map(int, input().split())) -        x -= 1 -        e[i].append((x, y)) -ret = 0 -for mask in range(1 << n): -    t = [(mask >> i) & 1 for i in range(n)] -    flg = True -    for i in range(n): -        if t[i]: -            for x, y in e[i]: -                if t[x] != y: -                    flg = False -                    break -            if not flg: -                break -    if flg: -        ret = max(ret, sum(t)) -print(ret) +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演算しようとしてはまった