import sys

import itertools

input = sys.stdin.readline



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

s = []

p = [0] * m

cnt_k = 0

cnt_j = 0

ans = 0



for i in range(m):

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

    s.append(s_k)

    

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



memo = list(itertools.product([0, 1], repeat=n))

for i in range(2 ** n):

    for j in range(m):

        for k in range(1, s[j][0] + 1):

            if memo[i][s[j][k] - 1] == 1:

                cnt_k += 1



        if cnt_k % 2 == p[j]:

            cnt_j += 1

        cnt_k = 0



    if cnt_j == m:

        ans += 1



    cnt_j = 0

print(ans)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



from itertools import product



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

ks = [list(map(int, readline().split()))[1:] for _ in range(m)]

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

ans = 0

for bit in product([0, 1], repeat=n):

    for pp, ksi in zip(p, ks):

        cnt = 0

        for j in range(n):

            if bit[j] == 1 and (j + 1) in ksi:

                cnt += 1

        if cnt % 2 != pp:

            break

    else:

        ans += 1



print(ans)

import sys
import itertools

input = sys.stdin.readline
n, m = list(map(int, input().split()))
s = []
p = [0] * m
cnt_k = 0
cnt_j = 0
ans = 0
for i in range(m):
    s_k = list(map(int, input().split()))
    s.append(s_k)
p = list(map(int, input().split()))
memo = list(itertools.product([0, 1], repeat=n))
for i in range(2**n):
    for j in range(m):
        for k in range(1, s[j][0] + 1):
            if memo[i][s[j][k] - 1] == 1:
                cnt_k += 1
        if cnt_k % 2 == p[j]:
            cnt_j += 1
        cnt_k = 0
    if cnt_j == m:
        ans += 1
    cnt_j = 0
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from itertools import product

n, m = list(map(int, readline().split()))
ks = [list(map(int, readline().split()))[1:] for _ in range(m)]
p = list(map(int, readline().split()))
ans = 0
for bit in product([0, 1], repeat=n):
    for pp, ksi in zip(p, ks):
        cnt = 0
        for j in range(n):
            if bit[j] == 1 and (j + 1) in ksi:
                cnt += 1
        if cnt % 2 != pp:
            break
    else:
        ans += 1
print(ans)

-import itertools -input = sys.stdin.readline -n, m = list(map(int, input().split())) -s = [] -p = [0] * m -cnt_k = 0 -cnt_j = 0 +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +sys.setrecursionlimit(10**7) +from itertools import product + +n, m = list(map(int, readline().split())) +ks = [list(map(int, readline().split()))[1:] for _ in range(m)] +p = list(map(int, readline().split())) -for i in range(m): -    s_k = list(map(int, input().split())) -    s.append(s_k) -p = list(map(int, input().split())) -memo = list(itertools.product([0, 1], repeat=n)) -for i in range(2**n): -    for j in range(m): -        for k in range(1, s[j][0] + 1): -            if memo[i][s[j][k] - 1] == 1: -                cnt_k += 1 -        if cnt_k % 2 == p[j]: -            cnt_j += 1 -        cnt_k = 0 -    if cnt_j == m: +for bit in product([0, 1], repeat=n): +    for pp, ksi in zip(p, ks): +        cnt = 0 +        for j in range(n): +            if bit[j] == 1 and (j + 1) in ksi: +                cnt += 1 +        if cnt % 2 != pp: +            break +    else: -    cnt_j = 0