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

ks = [list(map(int, input().split())) for _ in range(M)]

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

# print(N, M)

# print(ks)

# print(p)



ans = 0



import itertools

for i in itertools.product([0,1], repeat=N):

  righted = 0

  for iter, j in enumerate(ks):

  #  print(iter, j )

    cnt = 0

    for k in range(1,len(j)):

      cnt += i[j[k]-1]

    if cnt % 2 == p[iter]:

      righted += 1

  if len(ks) == righted:

    ans += 1

    

print(ans)

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

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

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

  

ans = 0

for b in range(2 ** n):

  onswitch = [i + 1 for i in range(n) if (b >> i) & 1]

  if all(sum(o in s for o in onswitch) % 2 == p for s, p in zip(S, P)):

    ans += 1

    

print(ans)
N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
# print(N, M)
# print(ks)
# print(p)
ans = 0
import itertools

for i in itertools.product([0, 1], repeat=N):
    righted = 0
    for iter, j in enumerate(ks):
        #  print(iter, j )
        cnt = 0
        for k in range(1, len(j)):
            cnt += i[j[k] - 1]
        if cnt % 2 == p[iter]:
            righted += 1
    if len(ks) == righted:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
S = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
ans = 0
for b in range(2**n):
    onswitch = [i + 1 for i in range(n) if (b >> i) & 1]
    if all(sum(o in s for o in onswitch) % 2 == p for s, p in zip(S, P)):
        ans += 1
print(ans)

-N, M = list(map(int, input().split())) -ks = [list(map(int, input().split())) for _ in range(M)] -p = list(map(int, input().split())) -# print(N, M) -# print(ks) -# print(p) +n, m = list(map(int, input().split())) +S = [list(map(int, input().split()))[1:] for _ in range(m)] +P = list(map(int, input().split())) -import itertools - -for i in itertools.product([0, 1], repeat=N): -    righted = 0 -    for iter, j in enumerate(ks): -        #  print(iter, j ) -        cnt = 0 -        for k in range(1, len(j)): -            cnt += i[j[k] - 1] -        if cnt % 2 == p[iter]: -            righted += 1 -    if len(ks) == righted: +for b in range(2**n): +    onswitch = [i + 1 for i in range(n) if (b >> i) & 1] +    if all(sum(o in s for o in onswitch) % 2 == p for s, p in zip(S, P)):