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

bulbs = []

for i in range(M):

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

    bulbs.append((k, s))

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



ans = 0

for i in range(1 << N):

    on_cnt = [0] * M

    for j in range(N):

        if i >> j & 1:

            for k in range(M):

                if j + 1 in bulbs[k][1]:

                    on_cnt[k] ^= 1

    if on_cnt == p:

        ans += 1

print(ans)

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

bulbs = []

for i in range(M):

    _, *conn_switches = list(map(int, input().split()))

    bulbs.append(conn_switches)

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



ans = 0

for i in range(1 << N):

    on_cnt = [0] * M

    for j, conn_switches in enumerate(bulbs):

        if P[j] ^ sum(i >> s - 1 & 1 for s in conn_switches) & 1:

            break

    else:

        ans += 1

print(ans)

N, M = list(map(int, input().split()))
bulbs = []
for i in range(M):
    k, *s = list(map(int, input().split()))
    bulbs.append((k, s))
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
    on_cnt = [0] * M
    for j in range(N):
        if i >> j & 1:
            for k in range(M):
                if j + 1 in bulbs[k][1]:
                    on_cnt[k] ^= 1
    if on_cnt == p:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
bulbs = []
for i in range(M):
    _, *conn_switches = list(map(int, input().split()))
    bulbs.append(conn_switches)
P = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
    on_cnt = [0] * M
    for j, conn_switches in enumerate(bulbs):
        if P[j] ^ sum(i >> s - 1 & 1 for s in conn_switches) & 1:
            break
    else:
        ans += 1
print(ans)

-    k, *s = list(map(int, input().split())) -    bulbs.append((k, s)) -p = list(map(int, input().split())) +    _, *conn_switches = list(map(int, input().split())) +    bulbs.append(conn_switches) +P = list(map(int, input().split())) -    for j in range(N): -        if i >> j & 1: -            for k in range(M): -                if j + 1 in bulbs[k][1]: -                    on_cnt[k] ^= 1 -    if on_cnt == p: +    for j, conn_switches in enumerate(bulbs): +        if P[j] ^ sum(i >> s - 1 & 1 for s in conn_switches) & 1: +            break +    else: