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

S=[]

for i in range(M):

  S.append(list(map(int,input().split())))

  S[-1]=S[-1][1:]

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



ans=0

for i in range(2**N):

  bit=format(i,'0'+str(N)+'b')

  bit=list(map(int,bit))

  on=0

  for s,p in zip(S,P):

    check=0

    for j in s:

      j-=1

      check+=bit[j]

    if check%2==p:on+=1

  if on==M:ans+=1  

print(ans)
n,m=list(map(int,input().split()))

K=[]

S=[]

for i in range(m):

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

  K.append(tmp[0])

  S.append(tmp[1:])

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

ans=0

for i in range(2**n):

  bit=format(i,'0'+str(n)+'b')

  bit=list(map(int,bit))

  on_den=0

  for den in range(m):

    on_swi=0

    for s in S[den]:

      on_swi+=bit[s-1]

    if on_swi%2==P[den]:

      on_den+=1

  if on_den==m:

    ans+=1

print(ans)
N, M = list(map(int, input().split()))
S = []
for i in range(M):
    S.append(list(map(int, input().split())))
    S[-1] = S[-1][1:]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    bit = format(i, "0" + str(N) + "b")
    bit = list(map(int, bit))
    on = 0
    for s, p in zip(S, P):
        check = 0
        for j in s:
            j -= 1
            check += bit[j]
        if check % 2 == p:
            on += 1
    if on == M:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
K = []
S = []
for i in range(m):
    tmp = list(map(int, input().split()))
    K.append(tmp[0])
    S.append(tmp[1:])
P = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    bit = format(i, "0" + str(n) + "b")
    bit = list(map(int, bit))
    on_den = 0
    for den in range(m):
        on_swi = 0
        for s in S[den]:
            on_swi += bit[s - 1]
        if on_swi % 2 == P[den]:
            on_den += 1
    if on_den == m:
        ans += 1
print(ans)

-N, M = list(map(int, input().split())) +n, m = list(map(int, input().split())) +K = [] -for i in range(M): -    S.append(list(map(int, input().split()))) -    S[-1] = S[-1][1:] +for i in range(m): +    tmp = list(map(int, input().split())) +    K.append(tmp[0]) +    S.append(tmp[1:]) -for i in range(2**N): -    bit = format(i, "0" + str(N) + "b") +for i in range(2**n): +    bit = format(i, "0" + str(n) + "b") -    on = 0 -    for s, p in zip(S, P): -        check = 0 -        for j in s: -            j -= 1 -            check += bit[j] -        if check % 2 == p: -            on += 1 -    if on == M: +    on_den = 0 +    for den in range(m): +        on_swi = 0 +        for s in S[den]: +            on_swi += bit[s - 1] +        if on_swi % 2 == P[den]: +            on_den += 1 +    if on_den == m: