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



sss = []

for _ in range(M):

    k, *ss = [int(x) - 1 for x in input().split()]

    sss.append(ss)

ps = list([x == '0' for x in input().split()])



# 全てのスイッチのパターンをチェック

cnt = 0

for i in range(2 ** N):

    lights = ps[:]

    for j, ss in enumerate(sss):

        for s in ss:

            if i >> s & 1:

                lights[j] = not lights[j]

    if all(lights):

        cnt += 1



print(cnt)
import itertools



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

skss = []

for _ in range(M):

    k, *sks = list(map(int, input().split()))

    skss.append(set(sks))

pMs = list([x == '0' for x in input().split()])



count = 0

for i in range(2 ** N):

    pMstmp = pMs[:]

    for j, b in enumerate(format(i, '0' + str(N) + 'b')):

        if b == '0':

            continue

        for k, sks in enumerate(skss):

            if j + 1 in sks:

                pMstmp[k] = not pMstmp[k]

    if all(pMstmp):

        count += 1



print(count)
N, M = list(map(int, input().split()))
sss = []
for _ in range(M):
    k, *ss = [int(x) - 1 for x in input().split()]
    sss.append(ss)
ps = list([x == "0" for x in input().split()])
# 全てのスイッチのパターンをチェック
cnt = 0
for i in range(2**N):
    lights = ps[:]
    for j, ss in enumerate(sss):
        for s in ss:
            if i >> s & 1:
                lights[j] = not lights[j]
    if all(lights):
        cnt += 1
print(cnt)

import itertools

N, M = list(map(int, input().split()))
skss = []
for _ in range(M):
    k, *sks = list(map(int, input().split()))
    skss.append(set(sks))
pMs = list([x == "0" for x in input().split()])
count = 0
for i in range(2**N):
    pMstmp = pMs[:]
    for j, b in enumerate(format(i, "0" + str(N) + "b")):
        if b == "0":
            continue
        for k, sks in enumerate(skss):
            if j + 1 in sks:
                pMstmp[k] = not pMstmp[k]
    if all(pMstmp):
        count += 1
print(count)

+import itertools + -sss = [] +skss = [] -    k, *ss = [int(x) - 1 for x in input().split()] -    sss.append(ss) -ps = list([x == "0" for x in input().split()]) -# 全てのスイッチのパターンをチェック -cnt = 0 +    k, *sks = list(map(int, input().split())) +    skss.append(set(sks)) +pMs = list([x == "0" for x in input().split()]) +count = 0 -    lights = ps[:] -    for j, ss in enumerate(sss): -        for s in ss: -            if i >> s & 1: -                lights[j] = not lights[j] -    if all(lights): -        cnt += 1 -print(cnt) +    pMstmp = pMs[:] +    for j, b in enumerate(format(i, "0" + str(N) + "b")): +        if b == "0": +            continue +        for k, sks in enumerate(skss): +            if j + 1 in sks: +                pMstmp[k] = not pMstmp[k] +    if all(pMstmp): +        count += 1 +print(count)