#coding:utf-8

import itertools

import numpy as np

ls_S = []

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

for m in range(M):

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

    S = [s-1 for s in S]

    ls_S.append(S[1:])

ptns = list(itertools.product(list(range(0,2)), repeat=N))

ptns = np.array(ptns)

#print (ptns)

#print (ls_S)

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

def check(P,ls):

    for i in range(len(P)):

        if P[i] == ls[i]:

            pass

        else:

            return 0

    return 1

sm = 0        

for ptn in ptns:

    ans = []

    for S in ls_S:

        #print ("a",sum(ptn[S]))

        ans.append(sum(ptn[S])%2)

    #print (ans)

    sm += check(P,ans)

print (sm)

from itertools import product

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

S = []

for m in range(M):

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

    S.append(s[1:])

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



ans = 0

for c in product([0,1],repeat=N):

    ok = True

    for m in range(M):

        sm = 0

        for s in S[m]:

            sm += c[s-1]

        if sm % 2 != P[m]:

            ok = False

            break

    if ok:

        ans += 1

print (ans)

        

# coding:utf-8
import itertools
import numpy as np

ls_S = []
N, M = list(map(int, input().split()))
for m in range(M):
    S = list(map(int, input().split()))
    S = [s - 1 for s in S]
    ls_S.append(S[1:])
ptns = list(itertools.product(list(range(0, 2)), repeat=N))
ptns = np.array(ptns)
# print (ptns)
# print (ls_S)
P = list(map(int, input().split()))


def check(P, ls):
    for i in range(len(P)):
        if P[i] == ls[i]:
            pass
        else:
            return 0
    return 1


sm = 0
for ptn in ptns:
    ans = []
    for S in ls_S:
        # print ("a",sum(ptn[S]))
        ans.append(sum(ptn[S]) % 2)
    # print (ans)
    sm += check(P, ans)
print(sm)

from itertools import product

N, M = list(map(int, input().split()))
S = []
for m in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
P = list(map(int, input().split()))
ans = 0
for c in product([0, 1], repeat=N):
    ok = True
    for m in range(M):
        sm = 0
        for s in S[m]:
            sm += c[s - 1]
        if sm % 2 != P[m]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)

-# coding:utf-8 -import itertools -import numpy as np +from itertools import product -ls_S = [] +S = [] -    S = list(map(int, input().split())) -    S = [s - 1 for s in S] -    ls_S.append(S[1:]) -ptns = list(itertools.product(list(range(0, 2)), repeat=N)) -ptns = np.array(ptns) -# print (ptns) -# print (ls_S) +    s = list(map(int, input().split())) +    S.append(s[1:]) - - -def check(P, ls): -    for i in range(len(P)): -        if P[i] == ls[i]: -            pass -        else: -            return 0 -    return 1 - - -sm = 0 -for ptn in ptns: -    ans = [] -    for S in ls_S: -        # print ("a",sum(ptn[S])) -        ans.append(sum(ptn[S]) % 2) -    # print (ans) -    sm += check(P, ans) -print(sm) +ans = 0 +for c in product([0, 1], repeat=N): +    ok = True +    for m in range(M): +        sm = 0 +        for s in S[m]: +            sm += c[s - 1] +        if sm % 2 != P[m]: +            ok = False +            break +    if ok: +        ans += 1 +print(ans)