def main():

    N = int(eval(input()))

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

    for i in range(N):

        a = int(eval(input()))

        for j in range(a):

            x, y = (int(i) for i in input().split())

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

            # 人iは人xのことをyと言っている



    ans = 0

    for bit in range(1 << N):

        cur = 0

        good = True  # 矛盾がない

        for i in range(N):

            if bit & (1 << i):

                # 人iは正直者

                cur += 1

                for j, y in G[i]:

                    if (bit & (1 << j)) and y == 1:

                        continue

                    elif not(bit & (1 << j)) and y == 0:

                        continue

                    elif (bit & (1 << j)) and y == 0:

                        good = False

                        break

                    elif not(bit & (1 << j)) and y == 1:

                        good = False

                        break

            else:

                # 人iはうそつき

                for j, y in G[i]:

                    if (bit & (1 << j)) and y == 0:

                        continue

                    elif not(bit & (1 << j)) and y == 1:

                        continue

                    elif (bit & (1 << j)) and y == 0:

                        good = False

                        break

                    elif not(bit & (1 << j)) and y == 1:

                        good = False

                        break

        # print(bit, ":", good)

        if good:

            ans = max(ans, cur)

    print(ans)





if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

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

    for i in range(N):

        a = int(eval(input()))

        for j in range(a):

            x, y = (int(i) for i in input().split())

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

            # 人iは人xのことをyと言っている

    ans = 0

    for bit in range(1 << N):

        cur = 0

        good = True  # 矛盾がない

        for i in range(N):

            if bit & (1 << i):

                # 人iは正直者

                cur += 1

                for j, y in G[i]:

                    if (bit & (1 << j)) and y == 0:

                        good = False

                    elif not(bit & (1 << j)) and y == 1:

                        good = False

        # print(bit, ":", good)

        if good:

            ans = max(ans, cur)

    print(ans)





if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    for i in range(N):
        a = int(eval(input()))
        for j in range(a):
            x, y = (int(i) for i in input().split())
            G[i].append((x - 1, y))
            # 人iは人xのことをyと言っている
    ans = 0
    for bit in range(1 << N):
        cur = 0
        good = True  # 矛盾がない
        for i in range(N):
            if bit & (1 << i):
                # 人iは正直者
                cur += 1
                for j, y in G[i]:
                    if (bit & (1 << j)) and y == 1:
                        continue
                    elif not (bit & (1 << j)) and y == 0:
                        continue
                    elif (bit & (1 << j)) and y == 0:
                        good = False
                        break
                    elif not (bit & (1 << j)) and y == 1:
                        good = False
                        break
            else:
                # 人iはうそつき
                for j, y in G[i]:
                    if (bit & (1 << j)) and y == 0:
                        continue
                    elif not (bit & (1 << j)) and y == 1:
                        continue
                    elif (bit & (1 << j)) and y == 0:
                        good = False
                        break
                    elif not (bit & (1 << j)) and y == 1:
                        good = False
                        break
        # print(bit, ":", good)
        if good:
            ans = max(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    for i in range(N):
        a = int(eval(input()))
        for j in range(a):
            x, y = (int(i) for i in input().split())
            G[i].append((x - 1, y))
            # 人iは人xのことをyと言っている
    ans = 0
    for bit in range(1 << N):
        cur = 0
        good = True  # 矛盾がない
        for i in range(N):
            if bit & (1 << i):
                # 人iは正直者
                cur += 1
                for j, y in G[i]:
                    if (bit & (1 << j)) and y == 0:
                        good = False
                    elif not (bit & (1 << j)) and y == 1:
                        good = False
        # print(bit, ":", good)
        if good:
            ans = max(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

-                    if (bit & (1 << j)) and y == 1: -                        continue -                    elif not (bit & (1 << j)) and y == 0: -                        continue -                    elif (bit & (1 << j)) and y == 0: +                    if (bit & (1 << j)) and y == 0: -                        break -                        break -            else: -                # 人iはうそつき -                for j, y in G[i]: -                    if (bit & (1 << j)) and y == 0: -                        continue -                    elif not (bit & (1 << j)) and y == 1: -                        continue -                    elif (bit & (1 << j)) and y == 0: -                        good = False -                        break -                    elif not (bit & (1 << j)) and y == 1: -                        good = False -                        break