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

S = [list(map(int,input().split()))[1:] for i in range(m)]

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

ans = 0

#bit全探索

for bit in range(1<<n):

    on = []

    ok = True #全部の電球が光る

    for i in range(n):

        if (bit & (1<<i)):

            on.append(i+1)

    for i in range(m):

        p = P[i]

        c = 0

        for s in S[i]:

            if s in on: c+=1

        if c%2!=p: ok=False

    if ok:ans+=1

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

d = []

for i in range(m):

    d.append(list(map(int,input().split())))

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



ans = 0

def search(x):

    global ans

    cnt = 0

    for i in range(m):

        c = 0

        for j in d[i][1:]:

            if x[j-1]==1:

                c += 1

        if c%2==p[i]:

            cnt += 1

    if cnt==m:ans+=1



from itertools import product

o = product(list(range(2)),repeat=n)

for i in o:

    search(i)

print(ans)

n, m = list(map(int, input().split()))
S = [list(map(int, input().split()))[1:] for i in range(m)]
P = list(map(int, input().split()))
ans = 0
# bit全探索
for bit in range(1 << n):
    on = []
    ok = True  # 全部の電球が光る
    for i in range(n):
        if bit & (1 << i):
            on.append(i + 1)
    for i in range(m):
        p = P[i]
        c = 0
        for s in S[i]:
            if s in on:
                c += 1
        if c % 2 != p:
            ok = False
    if ok:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
d = []
for i in range(m):
    d.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans = 0


def search(x):
    global ans
    cnt = 0
    for i in range(m):
        c = 0
        for j in d[i][1:]:
            if x[j - 1] == 1:
                c += 1
        if c % 2 == p[i]:
            cnt += 1
    if cnt == m:
        ans += 1


from itertools import product

o = product(list(range(2)), repeat=n)
for i in o:
    search(i)
print(ans)

-S = [list(map(int, input().split()))[1:] for i in range(m)] -P = list(map(int, input().split())) +d = [] +for i in range(m): +    d.append(list(map(int, input().split()))) +p = list(map(int, input().split())) -# bit全探索 -for bit in range(1 << n): -    on = [] -    ok = True  # 全部の電球が光る -    for i in range(n): -        if bit & (1 << i): -            on.append(i + 1) + + +def search(x): +    global ans +    cnt = 0 -        p = P[i] -        for s in S[i]: -            if s in on: +        for j in d[i][1:]: +            if x[j - 1] == 1: -        if c % 2 != p: -            ok = False -    if ok: +        if c % 2 == p[i]: +            cnt += 1 +    if cnt == m: + + +from itertools import product + +o = product(list(range(2)), repeat=n) +for i in o: +    search(i)