import copy
N,M=map(int,input().split())
linkedBulb=[[] for i in range(N)]#各スイッチごとにつながってる電球
for i in range(M):
    S=[int(_) for _ in input().split()]
    for n,s in enumerate(S):
        if n==0:continue
        else:
            linkedBulb[s-1].append(i)
s=[1-int(i) for i in input().split()]
ans=0
for bit in range(2**N):
    start=copy.deepcopy(s)
    for j in range(N):
        if (bit>>j)&1:
            for todo in linkedBulb[j]:
                start[todo]=1-start[todo]
    if all(start):ans+=1
    print(ans)
