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

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

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

ans=0

for i in range(2**n):

    cnt=[0]*m

    for j in range(n):

        if (i>>j)&1==1:

            for k in range(m):

                if j+1 in switch[k][1:]:

                    cnt[k]+=1

    l=[i%2 for i in cnt]

    if l==p:

        ans+=1

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

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

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

ans=0



for i in range(2**n):

    tmp=[]

    cnt=[0]*n

    for j in range(n):

        if (i>>j)&1:

            tmp.append(j+1)

    for k in range(m):

        if len(set(tmp)&set(s[k]))%2!=p[k]:

            break

    else:

        ans+=1

print(ans)
n, m = list(map(int, input().split()))
switch = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    cnt = [0] * m
    for j in range(n):
        if (i >> j) & 1 == 1:
            for k in range(m):
                if j + 1 in switch[k][1:]:
                    cnt[k] += 1
    l = [i % 2 for i in cnt]
    if l == p:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    tmp = []
    cnt = [0] * n
    for j in range(n):
        if (i >> j) & 1:
            tmp.append(j + 1)
    for k in range(m):
        if len(set(tmp) & set(s[k])) % 2 != p[k]:
            break
    else:
        ans += 1
print(ans)

-switch = [list(map(int, input().split())) for i in range(m)] +s = [list(map(int, input().split()))[1:] for _ in range(m)] -    cnt = [0] * m +    tmp = [] +    cnt = [0] * n -        if (i >> j) & 1 == 1: -            for k in range(m): -                if j + 1 in switch[k][1:]: -                    cnt[k] += 1 -    l = [i % 2 for i in cnt] -    if l == p: +        if (i >> j) & 1: +            tmp.append(j + 1) +    for k in range(m): +        if len(set(tmp) & set(s[k])) % 2 != p[k]: +            break +    else: