import numpy as np

from itertools import product



N, M = list(map(int, input().split()))

switch = []



for i in range(M):

    switch.append(list(map(int, input().split()))[1:])



p = list(map(int, input().split()))



st = list(product([0,1],repeat=N))



ans = 0



for i, s in enumerate(st):

    tmp = []

    for j, sw in enumerate(switch):

        on = 0

        for x in sw:

            on += s[x-1]

        if (on%2)==p[j]:

            tmp.append(True)

        else:

            tmp.append(False)

    if all(tmp)==True:

        ans += 1



print(ans)
from collections import defaultdict



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

s = defaultdict(list)



for i in range(1, m + 1):

    _, *x = list(map(int, input().split()))

    for j in x:

        s[j].append(i)



p = list(map(int, input().split()))





ans = []

for i in range(2**n):

    tmp = [0] * len(p)

    for j in range(n):

        if ((i >> j) & 1):

            for k in s[j + 1]:

                tmp[k - 1] += 1

    if all([x % 2 == y for x, y in zip(tmp, p)]):

        ans.append(True)

    else:

        ans.append(False)



print((sum(ans)))
import numpy as np
from itertools import product

N, M = list(map(int, input().split()))
switch = []
for i in range(M):
    switch.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
st = list(product([0, 1], repeat=N))
ans = 0
for i, s in enumerate(st):
    tmp = []
    for j, sw in enumerate(switch):
        on = 0
        for x in sw:
            on += s[x - 1]
        if (on % 2) == p[j]:
            tmp.append(True)
        else:
            tmp.append(False)
    if all(tmp) == True:
        ans += 1
print(ans)

from collections import defaultdict

n, m = list(map(int, input().split()))
s = defaultdict(list)
for i in range(1, m + 1):
    _, *x = list(map(int, input().split()))
    for j in x:
        s[j].append(i)
p = list(map(int, input().split()))
ans = []
for i in range(2**n):
    tmp = [0] * len(p)
    for j in range(n):
        if (i >> j) & 1:
            for k in s[j + 1]:
                tmp[k - 1] += 1
    if all([x % 2 == y for x, y in zip(tmp, p)]):
        ans.append(True)
    else:
        ans.append(False)
print((sum(ans)))

-import numpy as np -from itertools import product +from collections import defaultdict -N, M = list(map(int, input().split())) -switch = [] -for i in range(M): -    switch.append(list(map(int, input().split()))[1:]) +n, m = list(map(int, input().split())) +s = defaultdict(list) +for i in range(1, m + 1): +    _, *x = list(map(int, input().split())) +    for j in x: +        s[j].append(i) -st = list(product([0, 1], repeat=N)) -ans = 0 -for i, s in enumerate(st): -    tmp = [] -    for j, sw in enumerate(switch): -        on = 0 -        for x in sw: -            on += s[x - 1] -        if (on % 2) == p[j]: -            tmp.append(True) -        else: -            tmp.append(False) -    if all(tmp) == True: -        ans += 1 -print(ans) +ans = [] +for i in range(2**n): +    tmp = [0] * len(p) +    for j in range(n): +        if (i >> j) & 1: +            for k in s[j + 1]: +                tmp[k - 1] += 1 +    if all([x % 2 == y for x, y in zip(tmp, p)]): +        ans.append(True) +    else: +        ans.append(False) +print((sum(ans)))