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

KS = [list(map(int, input().split())) for i in range(M)]

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



ans = 0

for i in range(2**N):

    bit = str(bin(i))[2:].zfill(N)

    for (_, *s), p in zip(KS, P):

        ons = 0

        for si in s:

            ons += int(bit[si-1])

        if ons % 2 != p:

            break

    else:

        ans += 1



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

KS = [list(map(int, input().split())) for i in range(M)]

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



ans = 0

for i in range(2**N):

    switches = bin(i)[2:].zfill(N)

    all_light_on = True

    for j in range(M):

        _, *S = KS[j]

        on = 0

        for k, s in enumerate(switches, 1):

            if s == '1' and k in S:

                on += 1

        if on % 2 == P[j]:

            continue

        else:

            all_light_on = False

            break

    if all_light_on:

        ans += 1

print(ans)
N, M = list(map(int, input().split()))
KS = [list(map(int, input().split())) for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    bit = str(bin(i))[2:].zfill(N)
    for (_, *s), p in zip(KS, P):
        ons = 0
        for si in s:
            ons += int(bit[si - 1])
        if ons % 2 != p:
            break
    else:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
KS = [list(map(int, input().split())) for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    switches = bin(i)[2:].zfill(N)
    all_light_on = True
    for j in range(M):
        _, *S = KS[j]
        on = 0
        for k, s in enumerate(switches, 1):
            if s == "1" and k in S:
                on += 1
        if on % 2 == P[j]:
            continue
        else:
            all_light_on = False
            break
    if all_light_on:
        ans += 1
print(ans)

-    bit = str(bin(i))[2:].zfill(N) -    for (_, *s), p in zip(KS, P): -        ons = 0 -        for si in s: -            ons += int(bit[si - 1]) -        if ons % 2 != p: +    switches = bin(i)[2:].zfill(N) +    all_light_on = True +    for j in range(M): +        _, *S = KS[j] +        on = 0 +        for k, s in enumerate(switches, 1): +            if s == "1" and k in S: +                on += 1 +        if on % 2 == P[j]: +            continue +        else: +            all_light_on = False -    else: +    if all_light_on: