import itertools



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

lights = []

for i in range(M):

    lights.append([int(x) for x in input().split()])

p = [int(x) for x in input().split()]



ans = 0

switches = 0b1111111111 >> (10 - N)

for _ in range(0, switches + 1):

    flag = True

    for i in range(M):

        s = 0

        for j in range(1, lights[i][0] + 1):

            s += (_ & (0b1 << (lights[i][j] - 1))) >> (lights[i][j] - 1)

        if s % 2 != p[i]:

            flag = False

    if flag:

        ans += 1



print(ans)

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

lights = []

for _ in range(M):

    lights.append([int(i) for i in input().split()])

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



ans = 0

for switch in range(0, 2**N):

    flag = True

    for i in range(M):

        s = 0

        for j in range(lights[i][0]):

            s += (switch >> (lights[i][j + 1] - 1)) & 0b1

        if s % 2 != p[i]:

            flag = False

    if flag:

        ans += 1



print(ans)

import itertools

N, M = list(map(int, input().split()))
lights = []
for i in range(M):
    lights.append([int(x) for x in input().split()])
p = [int(x) for x in input().split()]
ans = 0
switches = 0b1111111111 >> (10 - N)
for _ in range(0, switches + 1):
    flag = True
    for i in range(M):
        s = 0
        for j in range(1, lights[i][0] + 1):
            s += (_ & (0b1 << (lights[i][j] - 1))) >> (lights[i][j] - 1)
        if s % 2 != p[i]:
            flag = False
    if flag:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
lights = []
for _ in range(M):
    lights.append([int(i) for i in input().split()])
p = [int(i) for i in input().split()]
ans = 0
for switch in range(0, 2**N):
    flag = True
    for i in range(M):
        s = 0
        for j in range(lights[i][0]):
            s += (switch >> (lights[i][j + 1] - 1)) & 0b1
        if s % 2 != p[i]:
            flag = False
    if flag:
        ans += 1
print(ans)

-import itertools - -for i in range(M): -    lights.append([int(x) for x in input().split()]) -p = [int(x) for x in input().split()] +for _ in range(M): +    lights.append([int(i) for i in input().split()]) +p = [int(i) for i in input().split()] -switches = 0b1111111111 >> (10 - N) -for _ in range(0, switches + 1): +for switch in range(0, 2**N): -        for j in range(1, lights[i][0] + 1): -            s += (_ & (0b1 << (lights[i][j] - 1))) >> (lights[i][j] - 1) +        for j in range(lights[i][0]): +            s += (switch >> (lights[i][j + 1] - 1)) & 0b1