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

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

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

v=[0]*n

w=[]

z=0

count=0

ans=0

for i in range(2**n):

    for j in range(n):

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

            v[j]=1

    w.append(v)

    v=[0]*n

for i in range(2**n):

    for j in range(m):

        for k in range(1,len(x[j])):

            z+=(w[i][x[j][k]-1])

        if z%2==p[j]:

            count+=1

        z=0

    if count==m:

        ans+=1

    count=0



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

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

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

ans=0





for i in range(2**n):

    s = [0] * n

    flag=True

    for j in range(n):

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

            s[j]=1



    for k in range(m):

        count=0

        for l in range(a[k][0]):

            if s[a[k][l+1]-1]==1:

                count+=1

        if count%2!=p[k]:

            flag=False

            break

        if not flag:

            break



    if flag:

        ans+=1



print(ans)
n, m = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
v = [0] * n
w = []
z = 0
count = 0
ans = 0
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1:
            v[j] = 1
    w.append(v)
    v = [0] * n
for i in range(2**n):
    for j in range(m):
        for k in range(1, len(x[j])):
            z += w[i][x[j][k] - 1]
        if z % 2 == p[j]:
            count += 1
        z = 0
    if count == m:
        ans += 1
    count = 0
print(ans)

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

-x = [list(map(int, input().split())) for i in range(m)] +a = [list(map(int, input().split())) for i in range(m)] -v = [0] * n -w = [] -z = 0 -count = 0 +    s = [0] * n +    flag = True -        if (i >> j) & 1: -            v[j] = 1 -    w.append(v) -    v = [0] * n -for i in range(2**n): -    for j in range(m): -        for k in range(1, len(x[j])): -            z += w[i][x[j][k] - 1] -        if z % 2 == p[j]: -            count += 1 -        z = 0 -    if count == m: +        if (i >> j) & 1 == 1: +            s[j] = 1 +    for k in range(m): +        count = 0 +        for l in range(a[k][0]): +            if s[a[k][l + 1] - 1] == 1: +                count += 1 +        if count % 2 != p[k]: +            flag = False +            break +        if not flag: +            break +    if flag: -    count = 0