import numpy as np

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

D = [0]*M

for i in range(M):

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

    for j in temp[1:]:

        D[i] +=  2**(j-1)

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

ans = 0

for s in range(2**N):

    temp = True

    for i,d in enumerate(D):

        temp &= bin(s&d).count('1')%2==p[i]

    if temp:

        ans += 1

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

S = [0]*M

for i in range(M):

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

    for j in s[1:]:

        S[i] += 2**(j-1)

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

ans = 0

for b in range(2**N):

    tmp = True

    for i, s in enumerate(S):

        tmp &= bin(b&s).count('1')%2==p[i]

    if tmp:

        ans += 1

print(ans)
import numpy as np

N, M = list(map(int, input().split()))
D = [0] * M
for i in range(M):
    temp = list(map(int, input().split()))
    for j in temp[1:]:
        D[i] += 2 ** (j - 1)
p = list(map(int, input().split()))
ans = 0
for s in range(2**N):
    temp = True
    for i, d in enumerate(D):
        temp &= bin(s & d).count("1") % 2 == p[i]
    if temp:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
S = [0] * M
for i in range(M):
    s = list(map(int, input().split()))
    for j in s[1:]:
        S[i] += 2 ** (j - 1)
p = list(map(int, input().split()))
ans = 0
for b in range(2**N):
    tmp = True
    for i, s in enumerate(S):
        tmp &= bin(b & s).count("1") % 2 == p[i]
    if tmp:
        ans += 1
print(ans)

-import numpy as np - -D = [0] * M +S = [0] * M -    temp = list(map(int, input().split())) -    for j in temp[1:]: -        D[i] += 2 ** (j - 1) +    s = list(map(int, input().split())) +    for j in s[1:]: +        S[i] += 2 ** (j - 1) -for s in range(2**N): -    temp = True -    for i, d in enumerate(D): -        temp &= bin(s & d).count("1") % 2 == p[i] -    if temp: +for b in range(2**N): +    tmp = True +    for i, s in enumerate(S): +        tmp &= bin(b & s).count("1") % 2 == p[i] +    if tmp: