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

S = []

for _ in range(M):

    S.append(list(map(int, input().split()))[1:])

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

ans = 0

for bit in range(1 << N):

    for m in range(M):

        if p[m] != ([bin(bit)[2:].zfill(N)[s-1] for s in S[m]].count('1') % 2):

            break

    else:

        ans += 1

print(ans)

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

S = []

for _ in range(M):

    S.append(list(map(int, input().split()))[1:])

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

ans = 0

for bit in range(1 << N):

    for m in range(M):

        if sum([bit & (1 << (s-1)) > 0 for s in S[m]]) % 2 != P[m]:

            break

    else:

        ans += 1

print(ans)

N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    S.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
    for m in range(M):
        if p[m] != ([bin(bit)[2:].zfill(N)[s - 1] for s in S[m]].count("1") % 2):
            break
    else:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    S.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
    for m in range(M):
        if sum([bit & (1 << (s - 1)) > 0 for s in S[m]]) % 2 != P[m]:
            break
    else:
        ans += 1
print(ans)

-p = list(map(int, input().split())) +P = list(map(int, input().split())) -        if p[m] != ([bin(bit)[2:].zfill(N)[s - 1] for s in S[m]].count("1") % 2): +        if sum([bit & (1 << (s - 1)) > 0 for s in S[m]]) % 2 != P[m]: