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

ls = []

for _ in range(m):

    k, *s, = [int(x)-1 for x in input().split()]

    ls.append(s)

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

ans = 0





def dfs(x, s):

    global ans

    if x == n:

        for j in range(m):

            switchs = ls[j]

            cond = p[j]

            on_cnt = 0

            for switch in switchs:

                if int(s[switch]):

                    on_cnt += 1

            if on_cnt % 2 != cond:

                break

        else:

            ans += 1

    else:

        for c in "01":

            dfs(x+1, s+c)





dfs(0, "")

print(ans)

from itertools import product

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

S = []

for _ in range(m):

    k, *s = [int(x)-1 for x in input().split()]

    S.append(s)

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

ans = 0

for bit in product((0, 1), repeat=n):

    for j in range(m):

        switch_cnt = sum(bit[idx] for idx in S[j])

        if P[j] != switch_cnt % 2:

            break

    else:

        ans += 1

print(ans)
n, m = list(map(int, input().split()))
ls = []
for _ in range(m):
    (
        k,
        *s,
    ) = [int(x) - 1 for x in input().split()]
    ls.append(s)
p = list(map(int, input().split()))
ans = 0


def dfs(x, s):
    global ans
    if x == n:
        for j in range(m):
            switchs = ls[j]
            cond = p[j]
            on_cnt = 0
            for switch in switchs:
                if int(s[switch]):
                    on_cnt += 1
            if on_cnt % 2 != cond:
                break
        else:
            ans += 1
    else:
        for c in "01":
            dfs(x + 1, s + c)


dfs(0, "")
print(ans)

from itertools import product

n, m = list(map(int, input().split()))
S = []
for _ in range(m):
    k, *s = [int(x) - 1 for x in input().split()]
    S.append(s)
P = list(map(int, input().split()))
ans = 0
for bit in product((0, 1), repeat=n):
    for j in range(m):
        switch_cnt = sum(bit[idx] for idx in S[j])
        if P[j] != switch_cnt % 2:
            break
    else:
        ans += 1
print(ans)

+from itertools import product + -ls = [] +S = [] -    ( -        k, -        *s, -    ) = [int(x) - 1 for x in input().split()] -    ls.append(s) -p = list(map(int, input().split())) +    k, *s = [int(x) - 1 for x in input().split()] +    S.append(s) +P = list(map(int, input().split())) - - -def dfs(x, s): -    global ans -    if x == n: -        for j in range(m): -            switchs = ls[j] -            cond = p[j] -            on_cnt = 0 -            for switch in switchs: -                if int(s[switch]): -                    on_cnt += 1 -            if on_cnt % 2 != cond: -                break -        else: -            ans += 1 +for bit in product((0, 1), repeat=n): +    for j in range(m): +        switch_cnt = sum(bit[idx] for idx in S[j]) +        if P[j] != switch_cnt % 2: +            break -        for c in "01": -            dfs(x + 1, s + c) - - -dfs(0, "") +        ans += 1