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

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

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

ans=0

for i in range(2**N):

  lit=[0]*M

  for j,switch in enumerate(L):

    cnt=0

    for s in switch:

      if i>>(s-1)&1:

        cnt+=1

    if cnt%2==P[j]:

      lit[j]=1

    else:

      lit[j]=0

  if all(lit): ans+=1 

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

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

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

ans=0

for i in range(2**N):

  lit=[0]*M

  for j,switches in enumerate(L):

    cnt=0

    for s in switches:

      if i>>(s-1)&1:cnt+=1

    if cnt%2==P[j]:lit[j]=1

  if all(lit):ans+=1 

print(ans)
N, M = list(map(int, input().split()))
L = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    lit = [0] * M
    for j, switch in enumerate(L):
        cnt = 0
        for s in switch:
            if i >> (s - 1) & 1:
                cnt += 1
        if cnt % 2 == P[j]:
            lit[j] = 1
        else:
            lit[j] = 0
    if all(lit):
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
L = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    lit = [0] * M
    for j, switches in enumerate(L):
        cnt = 0
        for s in switches:
            if i >> (s - 1) & 1:
                cnt += 1
        if cnt % 2 == P[j]:
            lit[j] = 1
    if all(lit):
        ans += 1
print(ans)

-    for j, switch in enumerate(L): +    for j, switches in enumerate(L): -        for s in switch: +        for s in switches: -        else: -            lit[j] = 0