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

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

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



ans = 0



for i in range(2**n):

  light_on = 0

  for j in range(m):

    switch_on = 0

    for k in ks[j][1:]:

      if (i >> k-1) & 1:

        switch_on += 1

    if switch_on % 2 == p[j]:

      light_on += 1

  if light_on == m:

    ans += 1



print(ans)
from itertools import product



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



x = []

for i in range(m):

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



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



ans = 0

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

    for i, s in enumerate(x):

        if sum([j[k-1] == 1 for k in s]) % 2 != p[i]:

            break

            

    else:

        ans += 1



print(ans)
n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    light_on = 0
    for j in range(m):
        switch_on = 0
        for k in ks[j][1:]:
            if (i >> k - 1) & 1:
                switch_on += 1
        if switch_on % 2 == p[j]:
            light_on += 1
    if light_on == m:
        ans += 1
print(ans)

from itertools import product

n, m = list(map(int, input().split()))
x = []
for i in range(m):
    x.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for j in product([1, 0], repeat=n):
    for i, s in enumerate(x):
        if sum([j[k - 1] == 1 for k in s]) % 2 != p[i]:
            break
    else:
        ans += 1
print(ans)

+from itertools import product + -ks = [list(map(int, input().split())) for i in range(m)] +x = [] +for i in range(m): +    x.append(list(map(int, input().split()))[1:]) -for i in range(2**n): -    light_on = 0 -    for j in range(m): -        switch_on = 0 -        for k in ks[j][1:]: -            if (i >> k - 1) & 1: -                switch_on += 1 -        if switch_on % 2 == p[j]: -            light_on += 1 -    if light_on == m: +for j in product([1, 0], repeat=n): +    for i, s in enumerate(x): +        if sum([j[k - 1] == 1 for k in s]) % 2 != p[i]: +            break +    else: