#python3

graph = [[-1 for _ in range(15)] for _ in range(15)]

def main():
    n = int(input())
    for i in range(n):
        a = int(input())
        for j in range(a):
            x, y = map(int, input().split())
            graph[i][x-1] = y
            
    ans = 0
    for i in range(1<<15):
        h = [0]*15
        for k in range(n):
            if (i >> k) & 1:
                h[k] = 1

        f = True
        for i in range(15):
            if h[i] == 1:
                for j in range(n):
                    if graph[i][j] == -1:
                        continue
                    if graph[i][j] != h[j]:
                        f = False

        if f:
            ans = max(ans, sum(h))

    print(ans)
main()