N = int(input())
i = [[tuple(map(int, input().split())) for _ in range(int(input()))] for _ in range(N)]

ans = 0
for l in range(1 << N):
    ok = True
    for m in range(N):
        if l & (1 << m):
            for x, y in i[m]:
                if (l & 1 << x-1) and not y:
                    ok = False
                    break
                if not (l & 1 << x-1) and y:
                    ok = False
                    break
            if not ok:
                break
    if ok:
        ans = max(ans, sum(c == "1" for c in bin(l)))

print(ans)
