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

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

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



ans = 0

for ii in range(2**N):

    check = True

    for i in range(M):

        cnt = 0

        for j in range(1, len(ks[i])):

            if (ii >> (ks[i][j]-1)) & 1:

                cnt += 1

        if cnt % 2 != p[i]:

            check = False

            break

    if check:

        ans += 1

print(ans)
n, m = list(map(int, input().split()))

ks = [list(map(int, input().split())) for _ in range(m)]

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



ans = 0

for i in range(2**n):

    flag = True

    for j in range(m):

        cnt = 0

        for k in range(1, len(ks[j])):

            if (i >> (ks[j][k]-1)) & 1:

                cnt += 1

        if cnt % 2 != p[j]:

            flag = False

            break

    if flag:

        ans += 1

print(ans)
N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for ii in range(2**N):
    check = True
    for i in range(M):
        cnt = 0
        for j in range(1, len(ks[i])):
            if (ii >> (ks[i][j] - 1)) & 1:
                cnt += 1
        if cnt % 2 != p[i]:
            check = False
            break
    if check:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    flag = True
    for j in range(m):
        cnt = 0
        for k in range(1, len(ks[j])):
            if (i >> (ks[j][k] - 1)) & 1:
                cnt += 1
        if cnt % 2 != p[j]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

-N, M = list(map(int, input().split())) -ks = [list(map(int, input().split())) for _ in range(M)] +n, m = list(map(int, input().split())) +ks = [list(map(int, input().split())) for _ in range(m)] -for ii in range(2**N): -    check = True -    for i in range(M): +for i in range(2**n): +    flag = True +    for j in range(m): -        for j in range(1, len(ks[i])): -            if (ii >> (ks[i][j] - 1)) & 1: +        for k in range(1, len(ks[j])): +            if (i >> (ks[j][k] - 1)) & 1: -        if cnt % 2 != p[i]: -            check = False +        if cnt % 2 != p[j]: +            flag = False -    if check: +    if flag: