CodeEff/ECCO huggingface dataset:
# Original solution
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)


# Optimized solution
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)
# Original solution
N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
blst = []
cnt = 0
for i in range(2 ** N):
    slst = []
    for j in range(N):
        if i >> j & 1:
            slst.append(j)
    blst.append(slst)

for i in blst:
    ansF = False
    for j in range(M):
        ctmp1 = 0
        for k in i:
            if ks[j][1:].count(k + 1) == 1:
                ctmp1 += 1
        if ctmp1 % 2 == p[j]:
            ansF = True
        else:
            ansF = False
            break
    if ansF:
        cnt += 1

print(cnt)

# Optimized solution

def dfs(cnt):
    global ans
    if cnt == N:
        onF = True
        for i in range(M):
            tmp = 0
            for j in range(ks[i][0]):
                if bit[ks[i][j + 1] - 1] == 1:
                    tmp += 1
            if tmp % 2 != p[i]:
                onF = False
                break
        if onF:
            ans += 1
        return
    for i in range(2):
        bit[cnt] = i
        dfs(cnt + 1)


N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
bit = [0] * N
ans = 0
dfs(0)
print(ans)
# Original solution
n, m = list(map(int,input().split()))
k = []
s = []

for i in range(m):
    temp = list(map(int, input().split()))
    temp_k = temp[0]
    temp_s = temp[1:]
    k.append(temp_k)
    s.append(temp_s)

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

ans = 0
for i in range(2**n):
    on = bin(i)[2:].rjust(n,"0")
    cond = 0
    for j in range(m):
        cnt = sum(list(map(int,[on[k] for k in range(n) if k+1 in s[j]])))
        
        if cnt % 2 == p[j]:
            cond += 1

    if cond == m:
        ans += 1

print(ans)

# Optimized solution

N, M = list(map(int, input().split()))
K = []
S = []
for _ in range(M):
	tmp = list(map(int ,input().split()))
	K.append(tmp[0])
	tmp.pop(0)
	S.append(tmp)

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


ans = 0
for i in range(2**N):
	flg = [0 for _ in range(M)]
	for j in range(N):
		if i & (1 << j):
			for k in range(M):
				if j+1 in S[k]:
					flg[k] += 1

	cond = 1
	for l in range(M):
		if P[l] != (flg[l] % 2):
			cond = 0
			break

	if cond:
		ans += 1

print(ans)
# Original solution
N, M = list(map(int, input().split()))
kss = []
for i in range(M):
    tmp = list(map(int, input().split()))
    k = tmp[0]
    s = tmp[1:]
    kss.append([k, s])
ps = list(map(int, input().split()))

def check_on(s_all, s, p):
    oncnt = 0
    for i in s:
        if s_all[i]:
            oncnt += 1
    if oncnt % 2 == p:
        return True
    else:
        return False

def check_all_on(s_all, kss, ps):
    for i in range(M):
        s = kss[i][1]
        p = ps[i]
        if not check_on(s_all, s, p):
            return False
    return True


def rec(s_all, kss, ps, cnt):
    if len(s_all) == N+1:
        if check_all_on(s_all, kss, ps):
            cnt[0] += 1
            return
    else:
        s_all.append(0)
        rec(s_all, kss, ps, cnt)
        s_all.pop()

        s_all.append(1)
        rec(s_all, kss, ps, cnt)
        s_all.pop()

s_all = [0]
cnt = [0]
rec(s_all, kss, ps, cnt)
print((cnt[0]))


# Optimized solution
N, M = list(map(int, input().split()))
onptns = []
for i in range(M):
    k, *s= list(map(int, input().split()))
    onptn = 0
    for i in s:
        onptn += 1 << (i - 1)
    onptns.append(onptn)
ps = list(map(int, input().split()))

ans = 0

s = 0
while s < (1 << N):
    ans += 1
    for onptn, p in zip(onptns, ps):
        if bin(s & onptn).count('1') % 2 != p:
            ans -= 1
            break
    s += 1

print(ans)
# Original solution
N, M = list(map(int,input().split()))
K = []
S = []
for i in range(M):
    k = 0
    s = []
    k, *s = list(map(int,input().split()))
    K.append(k)
    S.append(s)
P = list(map(int,input().split()))
res = 0
for bit in range(1 << N):
    judge = True
    for i in range(M):
        cnt = 0
        for s in S[i]:
            cnt += (bit >> s-1) & 1
        if cnt % 2 != P[i]:
            judge = False
    if judge:
        res += 1
print(res)

# Optimized solution
N, M = list(map(int,input().split()))
K = []
S = []
for i in range(M):
    k = 0
    s = []
    k, *s = list(map(int,input().split()))
    K.append(k)
    S.append(s)
P = list(map(int,input().split()))
res = 0
for bit in range(1 << N):
    judge = True
    for i in range(M):
        cnt = 0
        for s in S[i]:
            cnt += (bit >> s-1) & 1
        if cnt % 2 != P[i]:
            judge = False
            break
    if judge:
        res += 1
print(res)
# Original solution
n, m = list(map(int, input().split()))
s = []
k = []
for i in range(m):
    s.append(list(map(int, input().split())))
    k.append(s[i].pop(0))
p = list(map(int, input().split()))

# 全点灯パターンの個数
ans = 0

# 点灯している電球の数
cnt_s_on = 0

# 電球jに繋がるONのスイッチの数
cnt_switch = 0

for i in range(2**n):
    # print(bin(i))
    # print(bin(i>>1))
    # print("----")

    # print("i: "+str(bin(i)))
    tmpS=[0]*m
    cnt_s_on = 0
    
    # すべての電球に対して調べる
    for j in range(m):
        cnt_switch = 0
        
        # 電球jに繋がるすべてのスイッチに対してON/OFFを調べる
        for K in range(k[j]):
            if ((i >> (s[j][K]-1)) & 1):
                # スイッチがONならONカウントに＋する
                cnt_switch += 1
        
        # print("cnt_switch: " + str(cnt_switch))
        # print("cnt_switch%2: " + str(cnt_switch%2))
        # print("p[j]: " + str(p[j]))
        if cnt_switch%2 == p[j]:
            # 電球jは点灯している
            cnt_s_on += 1
            tmpS[j] = 1
    
    # print("電球状況："+str(tmpS))
    # print("cnt_s_on: " + str(cnt_s_on))
    if cnt_s_on == m:
        ans += 1

    # print("----------")
print(ans)


# Optimized solution
n, m = list(map(int, input().split()))
s = []
k = []
for i in range(m):
    s.append(list(map(int, input().split())))
    k.append(s[i].pop(0))
p = list(map(int, input().split()))

# 全点灯パターンの個数
ans = 0

# 点灯している電球の数
cnt_s_on = 0

# 電球jに繋がるONのスイッチの数
cnt_switch = 0

for i in range(2**n):
    cnt_s_on = 0
    
    # すべての電球に対して調べる
    for j in range(m):
        cnt_switch = 0
        
        # 電球jに繋がるすべてのスイッチに対してON/OFFを調べる
        for K in range(k[j]):
            if ((i >> (s[j][K]-1)) & 1):
                # スイッチがONならONカウントに＋する
                cnt_switch += 1
        
        if cnt_switch%2 == p[j]:
            # 電球jは点灯している
            cnt_s_on += 1
    
    if cnt_s_on == m:
        ans += 1

print(ans)
# Original solution
n,m=list(map(int,input().split()))
sw=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))

ans=0
for i in range(2**n):
    f=1
    for j in range(m):
        c=0
        for x in sw[j][1:]:
            x-=1
            c+=(i>>x)&1
        if c%2!=p[j]:
            f=0
    ans+=1 if f else 0
print(ans)


# Optimized solution
n,m=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    ss=[0]*n
    cc=0
    for j in range(n):
        if i>>j&1:
            ss[j]=1
    for j in range(m):
        c=0
        k=s[j][0]
        for l in range(1,k+1):
            c+=ss[s[j][l]-1]
        if c%2==p[j]:
            cc+=1
    if cc==m:
        ans+=1
print(ans)
# Original solution
N, M = list(map(int, input().split()))
S = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

count = 0
for i in range(2 ** N):
    state = ''.join(list(reversed(str(bin(i))[2:].zfill(N))))
    flg = True
    for m in range(M):
        on = 0
        for s in S[m]:
            if state[s - 1] == '1':
                on += 1
        if on % 2 != P[m]:
            flg = False
            break
    if flg:
        count += 1
print(count)


# Optimized solution
# コンテスト中は無理やりなビット全探索[alias bit全探索]をしたが、正しく書き換えた

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

count = 0
for i in range(2 ** N):
    flg = True
    for m in range(M):
        on = 0
        for s in S[m]:
            if (i >> s - 1) & 1:
                on += 1
        if on % 2 != P[m]:
            flg = False
            break
    if flg:
        count += 1
print(count)
# Original solution
#!/usr/bin/env python3

MOD = 2  # type: int


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N,M = list(map(int,input().split()))
    from collections import defaultdict
    d = defaultdict()
    for i in range(M):
        l = list(map(int,input().split()))
        d[i] = l[1:]

    # for k,v in d.items():
    #     print(k,v)

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

    ans = 0
    import itertools
    s = ('on', 'off')
    for i in itertools.product(s, repeat=N):
        anst = 0
        for k,v in list(d.items()):
            if(len([x for x in v if(i[x-1] == 'on')])%2 == p[k]):
                anst += 1

        if(anst == M):
            ans += 1
    
    print(ans)



if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3

MOD = 2  # type: int



def main():
    N, M = list(map(int, input().split()))
    k = []
    s = []
    for i in range(M):
        l = input().split()
        k.append(l[0])
        s.append(list(map(int, l[1:])))
    p = list(map(int, input().split()))

    ans = 0
    
    for i in range(1<<N):
        t = [0] * M
        for j in range(N):
            if i>>j & 1:
                for r in range(M):
                    # print(j+1, s[r])
                    if j+1 in s[r]:
                        t[r] += 1
        f = True
        for j in range(M):
            if t[j]%2 != p[j]:
                f = False
        
        if f:
            ans += 1

    print(ans)
    
    

if __name__ == '__main__':
    main()
# Original solution
n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x)-1 for x in input().split()])
    denq.append(set(ks[1:]))
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    for j in range(n):
        # スイッチjがonの場合
        if (i>>j)&1:
            for idq, dq in enumerate(denq):
                # すべての電球に対して
                # スイッチjが電球に紐付けられていれば、onをカウント
                if j in dq:
                    kk[idq] += 1

    for idq in range(m):
        if P[idq] != kk[idq]%2:
            break
    else:
        ans += 1
print(ans)


# Optimized solution
n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x)-1 for x in input().split()])
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += switch_states[s]
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)
# Original solution
n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x)-1 for x in input().split()])
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += switch_states[s]
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)


# Optimized solution
n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x)-1 for x in input().split()])
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    # switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += (i>>s)&1
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)
# Original solution
n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x)-1 for x in input().split()])
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    # switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += (i>>s)&1
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x)-1 for x in input().split()])
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += switch_states[s]
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)
# Original solution
from itertools import product
n,m = list(map(int,(input().split())))
sw =[list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for bit in product([0, 1], repeat=n):
    ele = True
    for i in range(m):
        cnt = 0
        for j in sw[i][1:]:
            cnt += bit[j-1]
        if cnt % 2 != p[i]:
            ele = False
            break
    if ele:
        ans += 1        
print(ans)

# Optimized solution
from itertools import product
n,m = list(map(int,(input().split())))
sw =[list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for bit in product([0, 1], repeat=n):
    ele = True #全部点灯ならtrue
    for i in range(m): #電球1～mに対するループ
        cnt = 0
        for j in sw[i][1:]: #switch1～nに対するループ
            #print(j)
            cnt += bit[j-1]
        if cnt % 2 != p[i]:
            ele = False
            break
    if ele:
        ans += 1        
print(ans)
# Original solution
N, M = list(map(int, input().split()))

lights = []
for _ in range(M):
    S = list(map(int, input().split()))
    mask = 0
    for a in S[1:]:
        mask |= (1 << (a - 1))
    lights.append(mask)

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

ans = 0
for mask in range(1 << N):
    for state, p in zip(lights, P):
        cnt = 0
        for d in range(N):
            if ((1 << d) & state) > 0 and ((1 << d) & mask) > 0:
                cnt += 1
        if cnt % 2 != p:
            break
    else:
        ans += 1

print(ans)


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

S = []
for _ in range(M):
    s = tuple([int(a) - 1 for a in input().split()])[1:]
    S.append(s)

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

ans = 0
for state in range(1 << N):
    for p, s in zip(P, S):
        cnt = 0
        for i in s:
            cnt += 1 if (state & (1 << i)) > 0 else 0
        if cnt % 2 != p:
            break
    else:
        ans += 1

print(ans)
# Original solution
#ABC 128C
def main():
    import sys
    import itertools as ite
    N, M = list(map(int, sys.stdin.readline().split()))
    Light = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
    P = list(map(int, sys.stdin.readline().split()))
    S = list(ite.product([0,1], repeat=N)) #スイッチの状態
    ans = 0
    for s_state in S:
        L_result = [0 for _ in range(M)]
        for m in range(M):
            for s_no in Light[m][1:]:
                L_result[m] += s_state[s_no-1]
        L_result = list([x%2 for x in L_result])
        if P == L_result:
            ans +=1
    print(ans)

if __name__=='__main__':
    main()


# Optimized solution
#ABC128C
def main():
    import sys, itertools as ite
    N, M = list(map(int, sys.stdin.readline().split()))
    KS = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
    P = tuple(map(int, sys.stdin.readline().split()))
    
    #print(KS)
    #bit全探索
    SWS = tuple(ite.product([0,1], repeat=N)) 
    
    def judge(on_off):
        for i in range(M):
            on_cnt = 0
            for s in KS[i][1:]:
                on_cnt += on_off[s-1]
            if on_cnt %2 !=P[i]:
                return 0
        else:
            return 1
    ans = 0
    for on_off in SWS:
        ans +=judge(on_off)
    print(ans)






if __name__=='__main__':
    main()
# Original solution
# C - Switches
#bit全探索の練習問題
import copy

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

ks = []
for l in range(M):
    s = input().split()
    ks.append(s)
p = list(map(int, input().split()))

KS = []
for m in range(M):#列の数はМ
    box = list()
    for n in range(len(ks[m])):#M列の要素を数字に直す処理
        ks[m][n] = int(ks[m][n])
        box.append(ks[m][n])
    KS.append(box)            

swich = []
for o in range(M):#列の数はМ
    swi = list()
    for r in range(1,len(KS[o])):#k以外を取り出す
        swi.append(ks[o][r])
    swich.append(swi)
           
ans = 0
for i in range(1<<N):#全パターンは2**(スイッチの総数)
    SWICH = copy.deepcopy(swich)
    light_on = 0
    for j in range(N):
        mask = 1<< j#1をj個左にずらした2進数
        if i & mask != 0:#スイッチjがonの時
            continue
        else:#スイッチjがoffの時
            for y in range(M):#電球iごとに繰り返し
                if (j+1 in SWICH[y]) == True:#スイッチsiが電球iに接続されているとき
                    SWICH[y].remove(j+1)

    #onのみがSWICHに入っている
    flat_SWICH = []
    for a in range(len(SWICH)):
        for b in range(len(SWICH[a])):
            flat_SWICH.append(SWICH[a][b])
            
    for x in range(M):
        if (len(SWICH[x]) % 2) == p[x]:#onのスイッチの数を2で割った余りがPの値と等しい時
            light_on += 1
    if light_on == M:#onの電球の個数がMと等しい(全てon)時
        ans += 1
print(ans)

# Optimized solution
# 93 C - Switches
N,M = list(map(int,input().split()))
K = []
S = []
for _ in range(M):
    s = list(map(int,input().split())) 
    K.append(s[0])
    # 0-indexed
    s = [i-1 for i in s]
    S.append(s[1:])
P = list(map(int,input().split()))

ans = 0
for i in range(1<<N):
    swiches = [0]*N
    for j in range(N):
        mask = 1<<j
        # j 番目のスイッチが on のとき
        if i & mask != 0:
            swiches[j] = 1
        # j 番目のスイッチが off のとき
        else:
            continue

    # on の電球をカウント
    cnt_light = 0
    for m in range(M):
        cnt_swich = 0
        for s in S[m]:
            if swiches[s] == 1:
                cnt_swich += 1
        if cnt_swich%2 == P[m]:
            cnt_light += 1
    if cnt_light == M:
        ans += 1
print(ans)
# Original solution
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    # 標準入力を取得
    N, M = list(map(int, input().split()))
    k, s = [], []
    for m in range(M):
        l = list(map(int, input().split()))
        k_m, s_m = l[0], l[1:]
        k.append(k_m)
        s.append(s_m)
    p = list(map(int, input().split()))

    return N, M, k, s, p


def lights_on(M: int, s: list, p: list, switches: int) -> bool:
    """
    電球がすべて点灯しているかどうかを確認する.

    Args:\n
        M (int): 電球の数
        s (list): 電球に対応するスイッチ
        p (list): スイッチと電球の点灯の関係
        switches (int): スイッチの状態

    Returns:\n
        bool: 電球がすべて点灯していれば真、そうでなければ偽
    """
    result = True
    for m in range(M):
        switch_on_count = 0
        for s_m_km in s[m]:
            if switches & (1 << (s_m_km - 1)):
                switch_on_count += 1
        if switch_on_count % 2 != p[m]:
            result = False

    return result


def main(N: int, M: int, s: list, p: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): スイッチの数
        M (int): 電球の数
        s (list): 電球に対応するスイッチ
        p (list): スイッチと電球の点灯の関係
    """
    # 求解処理
    ans = 0
    for switches in range(1 << N):
        if lights_on(M, s, p, switches):
            ans += 1

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, M, k, s, p = get_input()

    # メイン処理
    main(N, M, s, p)


# Optimized solution
# -*- coding: utf-8 -*-
# 標準入力を取得
N, M = list(map(int, input().split()))
k, s = [], []
for m in range(M):
    l = list(map(int, input().split()))
    k.append(l[0])
    s.append(l[1:])
p = list(map(int, input().split()))

# 求解処理
ans = 0
for bit in range(1 << N):
    is_light_on = True
    for m in range(M):
        on_count = 0
        for s_i in s[m]:
            if ((bit >> (s_i - 1)) & 1):
                on_count += 1
        if on_count % 2 != p[m]:
            is_light_on = False
            break
    if is_light_on:
        ans += 1

# 結果出力
print(ans)
# Original solution
import sys
input = sys.stdin.readline

v = []
p = []
count = 0
m = 0
def rec(l, n):
	global count
	if len(l) == n:
		c = 0
		for k, sw in enumerate(v):
			st = set()
			for i in range(n):
				if l[i] == 1:
					st.add(i + 1)
			# print(st)
			if len(sw.intersection(st)) % 2 == p[k]:
				c += 1
		# print("c: {}".format(c))
		if c == m:
			count += 1
		# print(l)
		return
	l.append(0)
	rec(list(l), n)
	l.pop()
	l.append(1)
	rec(list(l), n)

def main():
	global v
	global p
	global m
	n, m = list(map(int, input().strip().split()))
	for i in range(m):
		tmp = list(map(int, input().strip().split()))
		v.append(set(tmp[1:]))
	p = list(map(int, input().strip().split()))
	rec([], n)
	print(count)

if __name__ == '__main__':
	main()


# Optimized solution
import sys
input = sys.stdin.readline

v = []
p = []
count = 0
m = 0
def rec(l, n):
	global count
	if len(l) == n:
		c = 0
		for k, sw in enumerate(v):
			st = set()
			for i in range(n):
				if l[i] == 1:
					st.add(i + 1)
			# print(st)
			if len(sw.intersection(st)) % 2 != p[k]:
				return
		# print("c: {}".format(c))
		count += 1
		# print(l)
		return
	l.append(0)
	rec(list(l), n)
	l.pop()
	l.append(1)
	rec(list(l), n)

def main():
	global v
	global p
	global m
	n, m = list(map(int, input().strip().split()))
	for i in range(m):
		tmp = list(map(int, input().strip().split()))
		v.append(set(tmp[1:]))
	p = list(map(int, input().strip().split()))
	rec([], n)
	print(count)

if __name__ == '__main__':
	main()
# Original solution
import sys
input = sys.stdin.readline

v = []
p = []
count = 0
m = 0
def rec(l, n):
	global count
	if len(l) == n:
		c = 0
		st = set()
		for i in range(n):
			if l[i] == 1:
				st.add(i + 1)
		for k, sw in enumerate(v):
			# print(st)
			if len(sw.intersection(st)) % 2 != p[k]:
				return
		# print("c: {}".format(c))
		count += 1
		# print(l)
		return
	l.append(0)
	rec(list(l), n)
	l.pop()
	l.append(1)
	rec(list(l), n)

def main():
	global v
	global p
	global m
	n, m = list(map(int, input().strip().split()))
	for i in range(m):
		tmp = list(map(int, input().strip().split()))
		v.append(set(tmp[1:]))
	p = list(map(int, input().strip().split()))
	rec([], n)
	print(count)

if __name__ == '__main__':
	main()


# Optimized solution
import sys
input = sys.stdin.readline

def main():
	n, m = list(map(int, input().strip().split()))
	A = [0] * n
	for i in range(m):
		sw = list(map(int, input().strip().split()))[1:]
		for e in sw:
			e -= 1
			A[e] |= 1 << i

	pl = list(map(int, input().strip().split()))
	p = 0
	for i, e in enumerate(pl):
		p |= e << i
		# p = p << i

	j = 0
	ans = 0
	while j < (1 << n):
		t = 0
		for i in range(n):
			if j >> i & 1:
				t ^= A[i]
		if t == p:
			ans += 1
		j += 1

	print(ans)

if __name__ == '__main__':
	main()