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

s = []

for _ in range(M):

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

    s.append(set([x - 1 for x in kss[1:]]))

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



ans = 0

for bit in range(1 << N):

    on_counts = [0] * M

    for i in range(N):

        if bit & (1 << i):

            for m in range(M):

                if i in s[m]:

                    on_counts[m] += 1

    if [x % 2 for x in on_counts] == p:

        ans += 1

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

B = [None] * M

for i in range(M):

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

    B[i] = [s - 1 for s in ks[1:]]

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



ans = 0

bit = 0

for bit in range(1 << N):

    for i, b in enumerate(B):

        if p[i] != (len([1 for s in b if bit & (1 << s)]) % 2):

            break

    else:

        ans += 1

print(ans)
N, M = list(map(int, input().split()))
s = []
for _ in range(M):
    kss = list(map(int, input().split()))
    s.append(set([x - 1 for x in kss[1:]]))
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
    on_counts = [0] * M
    for i in range(N):
        if bit & (1 << i):
            for m in range(M):
                if i in s[m]:
                    on_counts[m] += 1
    if [x % 2 for x in on_counts] == p:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
B = [None] * M
for i in range(M):
    ks = list(map(int, input().split()))
    B[i] = [s - 1 for s in ks[1:]]
p = list(map(int, input().split()))
ans = 0
bit = 0
for bit in range(1 << N):
    for i, b in enumerate(B):
        if p[i] != (len([1 for s in b if bit & (1 << s)]) % 2):
            break
    else:
        ans += 1
print(ans)

-s = [] -for _ in range(M): -    kss = list(map(int, input().split())) -    s.append(set([x - 1 for x in kss[1:]])) +B = [None] * M +for i in range(M): +    ks = list(map(int, input().split())) +    B[i] = [s - 1 for s in ks[1:]] +bit = 0 -    on_counts = [0] * M -    for i in range(N): -        if bit & (1 << i): -            for m in range(M): -                if i in s[m]: -                    on_counts[m] += 1 -    if [x % 2 for x in on_counts] == p: +    for i, b in enumerate(B): +        if p[i] != (len([1 for s in b if bit & (1 << s)]) % 2): +            break +    else: