from itertools import product



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

sss = []

for _ in range(M):

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

    sss.append(ss)

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



ans = 0

for ptn in product(list(range(2)), repeat=N):

    numL = 0

    for ss, p in zip(sss, ps):

        numON = 0

        for s in ss:

            numON += ptn[s-1]

        if numON%2 == p:

            numL += 1

    if numL == M:

        ans += 1



print(ans)

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

switchss = []

for _ in range(M):

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

    switchss.append([sw-1 for sw in sws])

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



ans = 0

for S in range(1<<N):

    for i in range(M):

        num = 0

        for sw in switchss[i]:

            if (S>>sw) & 1:

                num += 1

        if num%2 != ps[i]:

            break

    else:

        ans += 1



print(ans)

from itertools import product

N, M = list(map(int, input().split()))
sss = []
for _ in range(M):
    k, *ss = list(map(int, input().split()))
    sss.append(ss)
ps = list(map(int, input().split()))
ans = 0
for ptn in product(list(range(2)), repeat=N):
    numL = 0
    for ss, p in zip(sss, ps):
        numON = 0
        for s in ss:
            numON += ptn[s - 1]
        if numON % 2 == p:
            numL += 1
    if numL == M:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
switchss = []
for _ in range(M):
    k, *sws = list(map(int, input().split()))
    switchss.append([sw - 1 for sw in sws])
ps = list(map(int, input().split()))
ans = 0
for S in range(1 << N):
    for i in range(M):
        num = 0
        for sw in switchss[i]:
            if (S >> sw) & 1:
                num += 1
        if num % 2 != ps[i]:
            break
    else:
        ans += 1
print(ans)

-from itertools import product - -sss = [] +switchss = [] -    k, *ss = list(map(int, input().split())) -    sss.append(ss) +    k, *sws = list(map(int, input().split())) +    switchss.append([sw - 1 for sw in sws]) -for ptn in product(list(range(2)), repeat=N): -    numL = 0 -    for ss, p in zip(sss, ps): -        numON = 0 -        for s in ss: -            numON += ptn[s - 1] -        if numON % 2 == p: -            numL += 1 -    if numL == M: +for S in range(1 << N): +    for i in range(M): +        num = 0 +        for sw in switchss[i]: +            if (S >> sw) & 1: +                num += 1 +        if num % 2 != ps[i]: +            break +    else: