import numpy as np



def add1(s, i = -1):

    if s[i] == 0:

        s[i] = 1

        return s

    else:

        s[i] = 0

        return add1(s, i-1)

    

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



k = []

s = []



for i in range(0, m):

    ki, *si = list(map(int, input().split()))

    k.append(ki)

    s.append(si)



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



sw = np.zeros(n)



ons = 0

ans = 0

sums = 0



for i in range(0, 2**n):

    for j in range(0, m):

        for l in s[j]:

            ons += sw[l-1]

        if ons % 2 == p[j]:

            sums += 1

        ons = 0

    if sums == m:

        ans += 1

    sums = 0

    if i != 2**n - 1:

        sw = add1(sw)





print(ans)

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



s = [0] * m



for i in range(m):

    k, *li = list(map(int, input().split()))

    for j in range(k):

        s[i] += 2**(li[j]-1)



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





ans = 0



for i in range(2**n):

    tmp = True

    for j in range(m):

        if bin(i & s[j]).count("1") % 2 != p[j]:

            tmp = False

            break



    if tmp:

        ans += 1



print(ans)

import numpy as np


def add1(s, i=-1):
    if s[i] == 0:
        s[i] = 1
        return s
    else:
        s[i] = 0
        return add1(s, i - 1)


n, m = list(map(int, input().split()))
k = []
s = []
for i in range(0, m):
    ki, *si = list(map(int, input().split()))
    k.append(ki)
    s.append(si)
p = list(map(int, input().split()))
sw = np.zeros(n)
ons = 0
ans = 0
sums = 0
for i in range(0, 2**n):
    for j in range(0, m):
        for l in s[j]:
            ons += sw[l - 1]
        if ons % 2 == p[j]:
            sums += 1
        ons = 0
    if sums == m:
        ans += 1
    sums = 0
    if i != 2**n - 1:
        sw = add1(sw)
print(ans)

n, m = list(map(int, input().split()))
s = [0] * m
for i in range(m):
    k, *li = list(map(int, input().split()))
    for j in range(k):
        s[i] += 2 ** (li[j] - 1)
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    tmp = True
    for j in range(m):
        if bin(i & s[j]).count("1") % 2 != p[j]:
            tmp = False
            break
    if tmp:
        ans += 1
print(ans)

-import numpy as np - - -def add1(s, i=-1): -    if s[i] == 0: -        s[i] = 1 -        return s -    else: -        s[i] = 0 -        return add1(s, i - 1) - - -k = [] -s = [] -for i in range(0, m): -    ki, *si = list(map(int, input().split())) -    k.append(ki) -    s.append(si) +s = [0] * m +for i in range(m): +    k, *li = list(map(int, input().split())) +    for j in range(k): +        s[i] += 2 ** (li[j] - 1) -sw = np.zeros(n) -ons = 0 -sums = 0 -for i in range(0, 2**n): -    for j in range(0, m): -        for l in s[j]: -            ons += sw[l - 1] -        if ons % 2 == p[j]: -            sums += 1 -        ons = 0 -    if sums == m: +for i in range(2**n): +    tmp = True +    for j in range(m): +        if bin(i & s[j]).count("1") % 2 != p[j]: +            tmp = False +            break +    if tmp: -    sums = 0 -    if i != 2**n - 1: -        sw = add1(sw)