import sys

from pprint import pprint



def solve(n, info):

    ans = 0

    for i in range(2 ** n):

        true_info = {}

        p_info = [0] * n

        for j in range(n):

            if (i >> j) & 1:

                true_info[j] = info[j]

                for x, y in info[j]:

                    if y == 1:

                        true_info[x-1] = info[x-1]

                # pprint(info[j])

                p_info[j] = 1

        # print("p_info")

        # pprint(p_info)

        # print("true_info")

        # pprint(true_info)

        flag = True

        for _, info_list in list(true_info.items()):

            for x, y in info_list:

                if p_info[x-1] != y:

                    flag = False

                    break

            if not flag:

                break



        if flag:

            # pprint(true_info)

            ans = max(ans, sum(p_info))



    print(ans)



if __name__ == '__main__':

    n = int(sys.stdin.readline().strip())

    info = []

    for i in range(n):

        a = int(sys.stdin.readline().strip())

        info.append([])

        for _ in range(a):

            x, y = list(map(int, sys.stdin.readline().strip().split(" ")))

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

    

    # pprint(info)

    solve(n, info)
import sys

from pprint import pprint



def solve(n, info):

    ans = 0

    for i in range(2 ** n):

        true_info = {}

        p_info = [0] * n

        for j in range(n):

            if (i >> j) & 1:

                true_info[j] = info[j]

                # pprint(info[j])

                p_info[j] = 1

        # print("p_info")

        # pprint(p_info)

        # print("true_info")

        # pprint(true_info)

        flag = True

        for _, info_list in list(true_info.items()):

            for x, y in info_list:

                if p_info[x-1] != y:

                    flag = False

                    break

            if not flag:

                break



        if flag:

            # pprint(true_info)

            ans = max(ans, sum(p_info))



    print(ans)



if __name__ == '__main__':

    n = int(sys.stdin.readline().strip())

    info = []

    for i in range(n):

        a = int(sys.stdin.readline().strip())

        info.append([])

        for _ in range(a):

            x, y = list(map(int, sys.stdin.readline().strip().split(" ")))

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

    

    # pprint(info)

    solve(n, info)
import sys
from pprint import pprint


def solve(n, info):
    ans = 0
    for i in range(2**n):
        true_info = {}
        p_info = [0] * n
        for j in range(n):
            if (i >> j) & 1:
                true_info[j] = info[j]
                for x, y in info[j]:
                    if y == 1:
                        true_info[x - 1] = info[x - 1]
                # pprint(info[j])
                p_info[j] = 1
        # print("p_info")
        # pprint(p_info)
        # print("true_info")
        # pprint(true_info)
        flag = True
        for _, info_list in list(true_info.items()):
            for x, y in info_list:
                if p_info[x - 1] != y:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            # pprint(true_info)
            ans = max(ans, sum(p_info))
    print(ans)


if __name__ == "__main__":
    n = int(sys.stdin.readline().strip())
    info = []
    for i in range(n):
        a = int(sys.stdin.readline().strip())
        info.append([])
        for _ in range(a):
            x, y = list(map(int, sys.stdin.readline().strip().split(" ")))
            info[i].append((x, y))
    # pprint(info)
    solve(n, info)

import sys
from pprint import pprint


def solve(n, info):
    ans = 0
    for i in range(2**n):
        true_info = {}
        p_info = [0] * n
        for j in range(n):
            if (i >> j) & 1:
                true_info[j] = info[j]
                # pprint(info[j])
                p_info[j] = 1
        # print("p_info")
        # pprint(p_info)
        # print("true_info")
        # pprint(true_info)
        flag = True
        for _, info_list in list(true_info.items()):
            for x, y in info_list:
                if p_info[x - 1] != y:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            # pprint(true_info)
            ans = max(ans, sum(p_info))
    print(ans)


if __name__ == "__main__":
    n = int(sys.stdin.readline().strip())
    info = []
    for i in range(n):
        a = int(sys.stdin.readline().strip())
        info.append([])
        for _ in range(a):
            x, y = list(map(int, sys.stdin.readline().strip().split(" ")))
            info[i].append((x, y))
    # pprint(info)
    solve(n, info)

-                for x, y in info[j]: -                    if y == 1: -                        true_info[x - 1] = info[x - 1]