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(1<<N):

  sw=[False]*M

  for j in range(M):

    cnt=0

    for k in range(1,len(S[j])):

      if (i>>(S[j][k]-1))&1:

        cnt+=1

      else:

        flag=0

    if cnt%2==P[j]:

      sw[j]=True

  if all(sw):

    ans+=1

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

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

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

ans=0

for i in range(1<<N):

  judge=1

  for j in range(M):

    cnt=0

    for k in KS[j][1:]:

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

        cnt+=1

    if (cnt%2)!=p[j]:

      judge=0

  if judge==1:

    ans+=1

print(ans)
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(1 << N):
    sw = [False] * M
    for j in range(M):
        cnt = 0
        for k in range(1, len(S[j])):
            if (i >> (S[j][k] - 1)) & 1:
                cnt += 1
            else:
                flag = 0
        if cnt % 2 == P[j]:
            sw[j] = True
    if all(sw):
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
KS = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
    judge = 1
    for j in range(M):
        cnt = 0
        for k in KS[j][1:]:
            if i >> (k - 1) & 1:
                cnt += 1
        if (cnt % 2) != p[j]:
            judge = 0
    if judge == 1:
        ans += 1
print(ans)

-S = [list(map(int, input().split())) for _ in range(M)] -P = list(map(int, input().split())) +KS = [list(map(int, input().split())) for _ in range(M)] +p = list(map(int, input().split())) -    sw = [False] * M +    judge = 1 -        for k in range(1, len(S[j])): -            if (i >> (S[j][k] - 1)) & 1: +        for k in KS[j][1:]: +            if i >> (k - 1) & 1: -            else: -                flag = 0 -        if cnt % 2 == P[j]: -            sw[j] = True -    if all(sw): +        if (cnt % 2) != p[j]: +            judge = 0 +    if judge == 1: