import itertools



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



S = []

for i in range(M):

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

    S.append(s[1:])

    

P = [int(i) for i in input().split()]



A = [0, 1]

ans = 0

for i in itertools.product(A, repeat = N):

    flag = 0

    for j in range(M):

        cnt = 0

        for s in S[j]:

            if i[s - 1] == 1:

                cnt += 1

        if cnt % 2 != P[j]:

            flag = 1

    if flag == 0:

        ans += 1

        

print(ans)
import itertools

 

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

 

S = []

for i in range(M):

    k, *s = list(map(int, input().split()))

    S.append(s)

    

P = [int(i) for i in input().split()]

 

A = [0, 1]

ans = 0

for i in itertools.product(A, repeat = N):

    flag = 0

    for j in range(M):

        cnt = 0

        for s in S[j]:

            if i[s - 1] == 1:

                cnt += 1

        if cnt % 2 != P[j]:

            flag = 1

    if flag == 0:

        ans += 1

        

print(ans)
import itertools

N, M = list(map(int, input().split()))
S = []
for i in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
P = [int(i) for i in input().split()]
A = [0, 1]
ans = 0
for i in itertools.product(A, repeat=N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
print(ans)

import itertools

N, M = list(map(int, input().split()))
S = []
for i in range(M):
    k, *s = list(map(int, input().split()))
    S.append(s)
P = [int(i) for i in input().split()]
A = [0, 1]
ans = 0
for i in itertools.product(A, repeat=N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
print(ans)

-    s = list(map(int, input().split())) -    S.append(s[1:]) +    k, *s = list(map(int, input().split())) +    S.append(s)