from itertools import product

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()))

it = ["01"]*n



ans = 0

for b in product(*it):

    base_2 = "".join(b)

    for j in range(m):

        switchs = ls[j]

        cond = p[j]

        on_cnt = 0

        for switch in switchs:

            if int(base_2[switch]):

                on_cnt += 1

        if on_cnt % 2 != cond:

            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()))
ls = []
for _ in range(m):
    (
        k,
        *s,
    ) = [int(x) - 1 for x in input().split()]
    ls.append(s)
p = list(map(int, input().split()))
it = ["01"] * n
ans = 0
for b in product(*it):
    base_2 = "".join(b)
    for j in range(m):
        switchs = ls[j]
        cond = p[j]
        on_cnt = 0
        for switch in switchs:
            if int(base_2[switch]):
                on_cnt += 1
        if on_cnt % 2 != cond:
            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 - -it = ["01"] * n -for b in product(*it): -    base_2 = "".join(b) -    for j in range(m): -        switchs = ls[j] -        cond = p[j] -        on_cnt = 0 -        for switch in switchs: -            if int(base_2[switch]): -                on_cnt += 1 -        if on_cnt % 2 != cond: -            break + + +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 -        ans += 1 +        for c in "01": +            dfs(x + 1, s + c) + + +dfs(0, "")