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

k = [input().split() for _ in range(M)]

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

ans = 0

for n in range(2 ** N):

    is_mismatch = False

    for i in range(M):

        cnt = 0

        for si in k[i][1:]:

            if (n >> (int(si) - 1)) & 1:

                cnt = (cnt + 1) % 2

        if cnt != p[i]:

            is_mismatch = True

            break

    if not is_mismatch:

        ans += 1

    

print(ans)

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

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

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

ans = 0



for i in range(2 ** n):

    is_on = True

    for j in range(m):

        k = swtiches[j][0]

        s = swtiches[j][1:]

        cnt = 0

        for si in s:

            if i >> (si - 1) & 1:

                cnt += 1

        if cnt % 2 != p[j]:

            is_on = False

    if is_on:

        ans += 1



print(ans)
N, M = list(map(int, input().split()))
k = [input().split() for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for n in range(2**N):
    is_mismatch = False
    for i in range(M):
        cnt = 0
        for si in k[i][1:]:
            if (n >> (int(si) - 1)) & 1:
                cnt = (cnt + 1) % 2
        if cnt != p[i]:
            is_mismatch = True
            break
    if not is_mismatch:
        ans += 1
print(ans)

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

-N, M = list(map(int, input().split())) -k = [input().split() for _ in range(M)] +n, m = list(map(int, input().split())) +swtiches = [list(map(int, input().split())) for _ in range(m)] -for n in range(2**N): -    is_mismatch = False -    for i in range(M): +for i in range(2**n): +    is_on = True +    for j in range(m): +        k = swtiches[j][0] +        s = swtiches[j][1:] -        for si in k[i][1:]: -            if (n >> (int(si) - 1)) & 1: -                cnt = (cnt + 1) % 2 -        if cnt != p[i]: -            is_mismatch = True -            break -    if not is_mismatch: +        for si in s: +            if i >> (si - 1) & 1: +                cnt += 1 +        if cnt % 2 != p[j]: +            is_on = False +    if is_on: