n, m = list(map(int, input().split()))

bits = '0b' + '1' * n

s = []



for _ in range(m):

    i = [int(i) for i in input().split()]

    s.append(i[1:])



p = [int(i) for i in input().split()]

c = 0

for i in range(2**n):

    l = bin(i)[2:]

    b = (n - len(l)) * '0' + l

    addable = True

    for h, j in enumerate(s):

        d = 0

        for k in j:

            d += int(b[k - 1])

        if addable:

            addable = d % 2 == p[h]

    if addable:

        c += 1

print(c)
n, m = list(map(int, input().split()))

s = [[int(i) for i in input().split()[1:]] for _ in range(m)]

p = [int(i) for i in input().split()]

c = 0



for i in range(2**n):

    addable = True

    for j in range(m):

        d = sum(2 ** (k - 1) for k in s[j])

        if bin(i & d).count('1') % 2 != p[j]:

            addable = False

            break

    if addable:

        c += 1

print(c)

n, m = list(map(int, input().split()))
bits = "0b" + "1" * n
s = []
for _ in range(m):
    i = [int(i) for i in input().split()]
    s.append(i[1:])
p = [int(i) for i in input().split()]
c = 0
for i in range(2**n):
    l = bin(i)[2:]
    b = (n - len(l)) * "0" + l
    addable = True
    for h, j in enumerate(s):
        d = 0
        for k in j:
            d += int(b[k - 1])
        if addable:
            addable = d % 2 == p[h]
    if addable:
        c += 1
print(c)

n, m = list(map(int, input().split()))
s = [[int(i) for i in input().split()[1:]] for _ in range(m)]
p = [int(i) for i in input().split()]
c = 0
for i in range(2**n):
    addable = True
    for j in range(m):
        d = sum(2 ** (k - 1) for k in s[j])
        if bin(i & d).count("1") % 2 != p[j]:
            addable = False
            break
    if addable:
        c += 1
print(c)

-bits = "0b" + "1" * n -s = [] -for _ in range(m): -    i = [int(i) for i in input().split()] -    s.append(i[1:]) +s = [[int(i) for i in input().split()[1:]] for _ in range(m)] -    l = bin(i)[2:] -    b = (n - len(l)) * "0" + l -    for h, j in enumerate(s): -        d = 0 -        for k in j: -            d += int(b[k - 1]) -        if addable: -            addable = d % 2 == p[h] +    for j in range(m): +        d = sum(2 ** (k - 1) for k in s[j]) +        if bin(i & d).count("1") % 2 != p[j]: +            addable = False +            break