CodeEff/ECCO huggingface dataset:
# Original solution
# -*- coding:utf-8 -*-
from itertools import product

def solve():
    N, M = list(map(int, input().split()))
    K, S = [], []
    for _ in range(M):
        _in = list(map(int, input().split()))
        K.append(_in[0])
        S.append(_in[1:])
    P = list(map(int, input().split()))

    all_stats = product((0,1), repeat=N)
    ans = 0
    for stat in all_stats:
        is_ok = True
        for switch_i, switch in enumerate(S):
            on_num = 0
            for i in range(len(switch)):
                if stat[switch[i]-1] == 1:
                    on_num += 1
            if on_num%2 != P[switch_i]:
                is_ok = False
                break
        if is_ok:
            ans += 1
    print(ans)

if __name__ == "__main__":
    solve()


# Optimized solution
# -*- coding:utf-8 -*-
import itertools

def solve():
    N, M = list(map(int, input().split()))
    Ks, Ss = [], []
    for i in range(M):
        _in = list(map(int, input().split()))
        Ks.append(_in[0])
        Ss.append(_in[1:])
    Ps = list(map(int, input().split()))

    # 全探索でいける
    switches = itertools.product([0,1], repeat=N)
    ans = 0
    for switch in switches:
        is_ok = True
        for i in range(M):
            on_num = 0
            for s in Ss[i]:
                if switch[s-1] == 1:
                    on_num += 1
            if on_num%2 != Ps[i]:
                is_ok = False
                break
        
        if is_ok:
            ans += 1

    print(ans)
    



if __name__ == "__main__":
    solve()
# Original solution
N, M = list(map(int, input().split()))
switches_bulbs_connection = {}

for i in range(M):
    switches_bulbs_connection[i] = list(map(int, input().split()))[1:]
p = list(map(int, input().split()))
count = 0
flag = 0

for i in range(2 ** N):  # スイッチのon/offについてビット全探索
    switch_on_off = [0] * N
    bulb_stat = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            switch_on_off[j] += 1  # 各スイッチがonかoffか
    for k in range(M):  # 電球kについて調べる
        tmp = switches_bulbs_connection[k]
        for switch in tmp:
            if switch_on_off[switch-1]:
                bulb_stat[k] += 1
    for l in range(M):
        if bulb_stat[l] % 2 == p[l]:
            flag += 1
    if flag == M:
        count += 1
    flag = 0

print(count)


# Optimized solution
N, M = list(map(int, input().split()))
bulb = []
count = 0

for _ in range(M):
    tmp = list(map(int, input().split()))
    bulb.append(tmp[1:])

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

for i in range(2 ** N):
    switch = []
    for j in range(N):  # スイッチの押し方を全探索
        if (i >> j) & 1:
            switch.append(j+1)
    bulb_count = M
    for k in range(M):  # M個の電球それぞれがついているか判定
        tmp = bulb[k]  # tmpは電球k につながっているスイッチ
        switch_count = 0
        for num in tmp:  # 電球kのスイッチについて判定
            if num in switch:
                switch_count += 1
        if switch_count % 2 == P[k]:
            bulb_count -= 1
    if bulb_count == 0:
        count += 1

print(count)
# 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()))

# print(S)
# print(P)

ans = 0

for i in range(1 << N):
    # print(i)
    for m in range(M):
        cnt = 0
        for s in S[m]:  # Sは繋がっているスイッチの情報
            if i & (1 << (s-1)) != 0:
                cnt += 1
        if cnt % 2 != P[m]:
            break
    else:  # このelseはどういうこと
        ans += 1

print(ans)


# Optimized solution
N, M = list(map(int, input().split()))  # N個のスイッチ, M個の電球

# M個の電球がそれぞれどこのスイッチと繋がっているかを格納
SSS = [list(map(int, input().split()))[1:] for i in range(M)]
P = list(map(int, input().split()))

ans = 0

for i in range(1 << N):  # 2のN乗の値になる, bit全探索
    for mask in range(M):
        ans_2 = 0
        for s in SSS[mask]:
            if (1 << s-1) & i != 0:
                ans_2 += 1

        if ans_2 % 2 != P[mask]:
            break
    else:
        ans += 1

print(ans)
# Original solution
N, M = list(map(int, input().split()))
cnt = 0
K = list()
L = list()
for m in range(M):
    l = list(map(int, input().split()))
    k = l.pop(0)
    K.append(k)
    L.append(l)
P = list(map(int, input().split()))
for i in range(1<<N):
    flag = True
    for j in range(M):
        c = 0
        for l in range(K[j]):
            if i & (1<<L[j][l]-1):
                c += 1
        if c % 2 != P[j]:
            flag = False
    if flag:
        cnt += 1
print(cnt)

# Optimized solution
N, M = list(map(int, input().split()))
K = []
S = []
for m in range(M):
    l = list(map(int, input().split()))
    k = l.pop(0)
    K.append(k)
    S.append(l)
P = list(map(int, input().split()))
ans = 0
for n in range(1<<N):
    res = True
    for m in range(M):
        cnt = 0
        for q in range(K[m]):
            if n & (1<<S[m][q]-1):
                cnt += 1
        if cnt % 2 != P[m]:
            res = False
    if res:
        ans += 1
print(ans)
# Original solution
N,M = list(map(int,input().split()))
bulbs = []
for _ in range(M):
  bulbs.append(list(map(int,input().split())))
P = list(map(int,input().split()))
res = 0
for i in range(1<<N):
  on = []
  for j in range(N):
    if (i>>j)&1:
      on.append(j)

  ok = True
  for i,b in enumerate(bulbs):
    b = [ k-1 for k in b[1:] ]
    p = P[i]
    o = 0
    for s in on:
      if s in b: o += 1
    if o%2 != p:
      ok = False
      break

  if ok:
    res += 1

print(res)


# Optimized solution
# N switches, M bulbs
N,M = list(map(int,input().split()))
K = []
for i in range(M):
  lst = list(map(int,input().split()))
  K.append([i-1 for i in lst[1:] ])

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

for i in range(1<<N):
  on = []
  for j in range(N):
    if (i>>j)&1:
      on.append(j)

  flg = True
  for m in range(M):
    k = K[m]
    tmp = 0
    for s in k:
      if s in on:
        tmp += 1
    p = P[m]
    if tmp % 2 != p:
      flg = False
      break

  if flg:
    res += 1

print(res)
# Original solution
n,m=list(map(int,input().split()))
s=eval('list(map(int,input().split()[1:])),'*m)
*p,=list(map(int,input().split()))
a=0
r=range
for i in r(1<<n):
 c=[0]*m
 for j in r(n):
  for k in r(m):c[k]+=i>>j&1and j+1in s[k]
 a+=all(j==i%2for i,j in zip(c,p))
print(a)

# Optimized solution
I=lambda:list(map(int,input().split()))
n,m=I()
s=eval('I(),'*m)
p=I()
a=0
r=range
for i in r(1<<n):
 c=[0]*m
 for j in r(n):
  for k in r(m):c[k]+=i>>j&1and j+1in s[k][1:]
 a+=all(j==i%2for i,j in zip(c,p))
print(a)
# Original solution
N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    S.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
    for m in range(M):
        if p[m] != ([bin(bit)[2:].zfill(N)[s-1] for s in S[m]].count('1') % 2):
            break
    else:
        ans += 1
print(ans)


# Optimized solution
N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    S.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
    for m in range(M):
        if sum([bit & (1 << (s-1)) > 0 for s in S[m]]) % 2 != P[m]:
            break
    else:
        ans += 1
print(ans)
# Original solution
n,m = list(map(int,input().split()))
l = []
for i in range(1 << n):
    tmp = str(bin(i))[2:]
    l.append(tmp.zfill(n))
K = [list(map(int,input().split())) for _ in range(m)]
P = list(map(int,input().split()))
#print(P)
ans = 0
#print("----")
for i in range(len(l)):
    #スイッチの状態l[i]
    #付いている電球のリストO
    O = []
    for j in range(m):
        #電球のきになるすいっちの数K[j][0]
        ON = 0
        for ii in range(K[j][0]): #スイッチのリスト
            if l[i][K[j][ii+1] - 1] == "1":
                ON += 1
        if ON % 2 == P[j]:
            O.append(1)
        else:
            O.append(0)
    if sum(O) == m:
        #print(l[i])
        ans += 1
print(ans)



# Optimized solution
n,m = list(map(int,input().split()))
a = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))
ans = 0
for i in range(2**n):
    onoffs = [int(j) for j in list(bin(i)[2:].zfill(n))]
    Flag = True
    for lamp in range(m):
        k = a[lamp][0]
        info = [l - 1 for l in  a[lamp][1:]]
        tmp = 0
        for index in info:
            if onoffs[index]:
                tmp += 1
        if tmp % 2 != p[lamp]:
            Flag = False
            break
    if Flag:
        ans += 1
print(ans)
# Original solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, M = mi()
ks = []
for i in range(M):
    a = li()
    ks.append(a)
P = li()

cnt = 0
for i in range(2**N):
    x = bin(i)[2:].zfill(N)
    l = list(map(int, list(x)))
    flag = 1
    for i in range(M):
        num , *switchs = ks[i]
        if sum([l[sw-1] for sw in switchs]) % 2 != P[i]:
            flag = 0
            break
    if flag:
        cnt += 1

print(cnt)

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

from itertools import product

N, M = mi()
ks = []
for i in range(M):
    a = li()
    ks.append(a)
P = li()

cnt = 0

#for i in range(2**N):
    #x = bin(i)[2:].zfill(N)
    #l = list(map(int, list(x)))
for l in product([0, 1], repeat=N):
    for i in range(M):
        num , *switchs = ks[i]
        if sum([l[sw-1] for sw in switchs]) % 2 != P[i]:
            break
    else:
        cnt += 1

print(cnt)
# Original solution
import itertools
N,M = list(map(int,input().split()))
switch = [list(map(int,input().split())) for m in range(M)]
p = list(map(int,input().split()))
S = list(itertools.product([0,1], repeat=N))
ans = 0
for s in S:
    s_ok = 0
    for m in range(M):
        count = 0
        for i in range(1, len(switch[m])):
            if s[switch[m][i]-1] == 1:
                count += 1
        if count%2 == p[m]:
            s_ok += 1
        else:
            break
    if s_ok == M:
        ans += 1
print(ans)


# Optimized solution
import itertools
N,M = list(map(int,input().split()))
switch = [list(map(int,input().split())) for m in range(M)]
p = list(map(int,input().split()))
S = list(itertools.product([0,1], repeat=N))
ans = 0
for s in S:
    s_ok = 0
    for m in range(M):
        count = 0
        for i in range(1, switch[m][0]+1):
            if s[switch[m][i]-1] == 1:
                count += 1
        if count%2 == p[m]:
            s_ok += 1
        else:
            break
    if s_ok == M:
        ans += 1
print(ans)
# Original solution
N, M = list(map(int, input().split()))
K = [0] * M
for i in range(M):
  K[i] = list(map(int, input().split()))
  K[i].pop(0)
#print(K)

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

ans = 0
for i in range(2 ** N):#最大1000
  now = [0] * (N + 1)
  x = 1
  for j in range(N):#最大10
    if ((i >> j) & 1):
      now[j + 1] = 1
  for k in range(M):# 10 * 10
    now2 = 0
    for a in K[k]:
      if now[a] == 1:
        now2 += 1
    if now2 % 2 != p[k]:
      x = 0
  ans += x
  
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
K = [0] * M
for i in range(M):
  S = list(map(int, input().split()))
  K[i] = S[1:]
  
P = list(map(int, input().split()))
#print(K)

count = 0
for i in range(2 ** N):#1024
  on = [0] * N
  ans = [0] * M
  ans2 = [1] * M
  for j in range(N):#10
    if ((i >> j) & 1):
      on[j] = 1
  #print(on)
  for k in range(M):#10
    now = 0
    for l in K[k]:
      if on[l - 1] == 1:
        now += 1
    if now % 2 == P[k]:
      ans[k] = 1
  #print(on, ans)
  if ans == ans2:
    count += 1

print(count)
# Original solution
def slove():
    import sys
    import bisect
    import collections
    import fractions
    import heapq
    import itertools
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ks = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    p = list(map(int, input().rstrip('\n').split()))
    a_cnt = 0
    for v in itertools.product([True, False], repeat=n):
        b = True
        for j, vv in enumerate(ks):
            cnt = 0
            for i in range(vv[0]):
                if v[vv[i+1]-1]:
                    cnt += 1
            if cnt % 2 != p[j]:
                b = False
                break
        if b:
            a_cnt += 1
    print(a_cnt)


if __name__ == '__main__':
    slove()


# Optimized solution
import sys
import itertools


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    ks = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    p = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for v in itertools.product([True, False], repeat=n):
        b = True
        for i in range(m):
            t = 0
            for kv in ks[i][1:]:
                t += v[kv-1]
            if t % 2 != p[i]:
                b = False
                break
        if b:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()
# Original solution
N, M = list(map(int, input().split()))
slist = [list(map(int, input().split()))[1:] for _ in range(M)]
plist = list(map(int, input().split()))

def count_on_switch(switch_array: list, on: set):
    return sum([int(sw in on) for sw in switch_array])

ans = 0
# print("---")
for i in range(2**N):
    on = set()
    for j in range(N):
        if ((i >> j) & 1):
             on.add(j+1)
    temp = 0
    for _ in range(M):
        cou_on = count_on_switch(slist[_], on)
        # print(i, cou_on)
        if cou_on % 2 != plist[_]:
            break
    else:
        ans += 1
print(ans)


# Optimized solution
N, M = list(map(int, input().split()))
s_setlist = []
for i in range(M):
    k, *s = list(map(int, input().split()))
    s_setlist.append(set(s))
plist = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    on = set()
    for j in range(N):
        if ((i >> j) & 1):
            on.add(j+1)
    light_list = [len(on&s_setlist[k])%2==plist[k] for k in range(M)]
    if all(light_list):
        ans += 1
print(ans)
# Original solution
import itertools

N,M=list(map(int,input().split()))
sw=[list(map(int,input().split())) for _ in range(M)]
p=[int(x) for x in input().split()]
ans=0

for i in itertools.product([0,1],repeat=N):#i...スイッチの状態一覧
    onof=True

    for j in range(M):#j...電球の番号
        j_on_cnt=0#電球jに対するonスイッチの個数
    
        for k in sw[j][1:]:
            j_on_cnt+=i[k-1]
            
        if j_on_cnt%2!=p[j]:#電球jがonかoffなのかを調べる
            onof=False
            break
    if onof:
        ans+=1
        
print(ans)

# Optimized solution
import itertools

N,M=list(map(int,input().split()))
sw=[list(map(int,input().split())) for _ in range(M)]
p=[int(x) for x in input().split()]
ans=0

for i in itertools.product([0,1],repeat=N):
    ok=True
    for j in range(M):
        j_on_cnt=0
        for k in sw[j][1:]:
            j_on_cnt+=i[k-1]
        if j_on_cnt%2!=p[j]:
            ok=False
            break
    if ok:
        ans+=1
print(ans)
# Original 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):
	x = bin(i)[2:].rjust(N, "0")
	flag = True
	for j in range(M):
		tmp = 0
		for k in range(1, s[j][0] + 1):
			index = s[j][k]
			if x[index - 1] == "1":
				tmp += 1
		if tmp % 2 != p[j] % 2:
			flag = False
	if flag:
		ans += 1
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

# 0をoffとして2進数でパターンを表現

for i in range(2 ** N):
	x = bin(i)[2:].rjust(N, "0")
	light = True  # 着目している電球が点灯していないときはこれがFalseになる
	for j in range(M):
		tmp = 0  # 着目している電球について、スイッチのonの個数をカウントする
		for k in range(1, s[j][0] + 1):
			if x[s[j][k] - 1] == "1":
				tmp += 1
		if tmp % 2 != p[j] % 2:
			light = False
	if light:
		ans += 1
print(ans)
# Original 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

# 0をoffとして2進数でパターンを表現

for i in range(2 ** N):
	x = bin(i)[2:].rjust(N, "0")
	light = True  # 着目している電球が点灯していないときはこれがFalseになる
	for j in range(M):
		tmp = 0  # 着目している電球について、スイッチのonの個数をカウントする
		for k in range(1, s[j][0] + 1):
			if x[s[j][k] - 1] == "1":
				tmp += 1
		if tmp % 2 != p[j] % 2:
			light = False
	if light:
		ans += 1
print(ans)


# Optimized solution
N, M = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(M)]  #sの各要素のはじめはk
p = list(map(int, input().split()))
ans = 0

# 0をoffとして2進数でパターンを表現

for i in range(2 ** N):
	ptn = bin(i)[2:].rjust(N, "0")  # N桁の2進表現にする
	light = True  # 着目している電球が点灯していないときはこれがFalseになる
	for j in range(M):
		tmp = 0  # 着目している電球について、スイッチのonの個数をカウントする
		for n in range(1, s[j][0] + 1):
			if ptn[s[j][n] - 1] == "1":
				tmp += 1
		if tmp % 2 != p[j] % 2:
			light = False
	if light:
		ans += 1

print(ans)
# Original solution
n, m = list(map(int, input().split()))
switches = []
cnt = 0

for i in range(m):
    array = list(map(int, input().split()))
    array.pop(0)
    switches.append(array)

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


def ch_binary(l, digit):
    num = [0] * digit
    for i in l:
        num[i-1] = 1
    return num

#スイッチのON、OFFをバイナリで表現する。
switches_2 = []
for i in switches:
    array = ch_binary(i, n)
    switches_2.append(array)



def check(a, b, digit, x):
    count = 0
    for i in range(digit):
        if a[i] == b[i] and b[i] == 1:
            count += 1
    if count % 2 == x:
        return 1
    else:
        return 0


for i in range(2**n):
    bin_str = list(map(int, format(i, 'b').zfill(n)))
    count = 0
    for j in range(m):
        y = check(switches_2[j], bin_str, n, p[j])
        count += y
    if count == m:
        cnt += 1

print(cnt)


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

switches = []

for i in range(m):
    array = list(map(int, input().split()))
    switches.append(array[1:])

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

bit_size = 2 ** n

ans = 0

for i in range(bit_size):
    num = format(i, 'b').zfill(n)
    flag = True
    for j in range(m):
        a = 0
        for k in range(n):
            if num[k] == '1' and k+1 in switches[j]:
                a += 1
        if a % 2 == checker[j]:
            continue
        else:
            flag = False
            break
    if flag is True:
        ans += 1

print(ans)
# Original solution
def inpl(): return list(map(int, input().split()))

N, M = inpl()
T = [[] for _ in range(N)]
for i in range(M):
    _, *S = inpl()
    for s in S:
        T[s-1].append(i)
P = inpl()

ans = 0
for x in range(2**N):
    Q = [0]*M
    for i in range(N):
        if (x >> i) & 1:
            for t in T[i]:
                Q[t] += 1
    ans += P == [q%2 for q in Q]
print(ans)

# Optimized solution
def inpl(): return list(map(int, input().split()))
N, M = inpl()
L = [0]*M
for i in range(M):
    for s in inpl()[1:]:
        L[i] += pow(2, s-1)
P = inpl()
print((sum([sum([bin(L[j]&i).count("1")%2 == P[j] for j in range(M)]) == M for i in range(pow(2, N))])))
# Original solution
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):
  onswichi = [False] * n
  onlight = [0] * m
  for j in range(n):
    if (i >> j) & 1:
      onswichi[j] = True
  for k in range(m):
    cnt = 0
    for f in ks[k][1:]:
      if onswichi[f-1]:
        cnt += 1
    if cnt % 2 == p[k]:
      onlight[k] = 1
  if sum(onlight) == m:
    ans += 1
print(ans)

# Optimized solution
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):
    l = [False] * n
    for j in range(n):
        if (i>>j) & 1:
            l[j] = True
    for j in range(m):
        if [l[k-1] for k in ks[j][1:]].count(True) % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)
# Original solution
n, m = list(map(int, input().split()))
ls = []
for _ in range(m):
    k, *s, = [int(x)-1 for x in input().split()]
    ls.append(s)
p = list(map(int, input().split()))


def base_n(x, n, zero_padding=8):
    retval = [[], ['0']][x == 0]
    while x > 0:
        x, r = divmod(x, n)
        retval.append(str(r))
    cnt = zero_padding - len(retval)
    pad = ['', '0'*cnt][cnt > 0]
    return pad+''.join(retval[::-1])


ans = 0
for i in range(2**n):
    base_2 = base_n(i, 2, n)
    for j in range(m):
        switchs = ls[j]
        cond = p[j]

        on_cnt = 0
        for switch in switchs:
            if int(base_2[switch]):
                on_cnt += 1
        if on_cnt % 2 != cond:
            break

    else:
        ans += 1
print(ans)

# Optimized solution
from itertools import product
n, m = list(map(int, input().split()))
ls = []
for _ in range(m):
    k, *s, = [int(x)-1 for x in input().split()]
    ls.append(s)
p = list(map(int, input().split()))
it = ["01"]*n

ans = 0
for b in product(*it):
    base_2 = "".join(b)
    for j in range(m):
        switchs = ls[j]
        cond = p[j]
        on_cnt = 0
        for switch in switchs:
            if int(base_2[switch]):
                on_cnt += 1
        if on_cnt % 2 != cond:
            break
    else:
        ans += 1
print(ans)
# Original solution
from itertools import product
n, m = list(map(int, input().split()))
ls = []
for _ in range(m):
    k, *s, = [int(x)-1 for x in input().split()]
    ls.append(s)
p = list(map(int, input().split()))
it = ["01"]*n

ans = 0
for b in product(*it):
    base_2 = "".join(b)
    for j in range(m):
        switchs = ls[j]
        cond = p[j]
        on_cnt = 0
        for switch in switchs:
            if int(base_2[switch]):
                on_cnt += 1
        if on_cnt % 2 != cond:
            break
    else:
        ans += 1
print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
ls = []
for _ in range(m):
    k, *s, = [int(x)-1 for x in input().split()]
    ls.append(s)
p = list(map(int, input().split()))
ans = 0


def dfs(x, s):
    global ans
    if x == n:
        for j in range(m):
            switchs = ls[j]
            cond = p[j]
            on_cnt = 0
            for switch in switchs:
                if int(s[switch]):
                    on_cnt += 1
            if on_cnt % 2 != cond:
                break
        else:
            ans += 1
    else:
        for c in "01":
            dfs(x+1, s+c)


dfs(0, "")
print(ans)