from collections import deque





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

s = [0] * m

k = [0] * m

for i in range(m):

    s[i] = deque(list(map(int, input().split())))

    k[i] = deque.popleft(s[i])

    s[i] = list(s[i])

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

cnt = 0

for i in range(2 ** n):

    l = [0] * n

    for j in range(n):

        if (i >> j) & 1:

            l[j] = 1

    for k in range(m):

        total = 0

        ans = True

        for num in s[k]:

            idx = num - 1

            if l[idx] == 1:

                total += 1

        if total % 2 != p[k]:

            ans = False

            break

    if ans:

        cnt += 1

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

s = [0] * m

for i in range(m):

    s[i] = list(map(int, input().split()))[1:]

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

ans = 0

for bit in range(2 << (n-1)):

    l = [0] * n

    for i in range(n):

        if bit >> i & 1:

            l[i] += 1

    for i in range(m):

        cnt = 0

        flag = True

        for j in s[i]:

            if l[j-1] == 1:

                cnt += 1

        if cnt % 2 != p[i]:

            flag = False

            break

    if flag:

        ans += 1

print(ans)

from collections import deque

n, m = list(map(int, input().split()))
s = [0] * m
k = [0] * m
for i in range(m):
    s[i] = deque(list(map(int, input().split())))
    k[i] = deque.popleft(s[i])
    s[i] = list(s[i])
p = list(map(int, input().split()))
cnt = 0
for i in range(2**n):
    l = [0] * n
    for j in range(n):
        if (i >> j) & 1:
            l[j] = 1
    for k in range(m):
        total = 0
        ans = True
        for num in s[k]:
            idx = num - 1
            if l[idx] == 1:
                total += 1
        if total % 2 != p[k]:
            ans = False
            break
    if ans:
        cnt += 1
print(cnt)

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

-from collections import deque - -k = [0] * m -    s[i] = deque(list(map(int, input().split()))) -    k[i] = deque.popleft(s[i]) -    s[i] = list(s[i]) +    s[i] = list(map(int, input().split()))[1:] -cnt = 0 -for i in range(2**n): +ans = 0 +for bit in range(2 << (n - 1)): -    for j in range(n): -        if (i >> j) & 1: -            l[j] = 1 -    for k in range(m): -        total = 0 -        ans = True -        for num in s[k]: -            idx = num - 1 -            if l[idx] == 1: -                total += 1 -        if total % 2 != p[k]: -            ans = False +    for i in range(n): +        if bit >> i & 1: +            l[i] += 1 +    for i in range(m): +        cnt = 0 +        flag = True +        for j in s[i]: +            if l[j - 1] == 1: +                cnt += 1 +        if cnt % 2 != p[i]: +            flag = False -    if ans: -        cnt += 1 -print(cnt) +    if flag: +        ans += 1 +print(ans)