N,M=list(map(int,input().split()))





S=[0 for i in range(N)]

A=[]



for x in range(M):

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

    X=[]

    for y in range(1,s[0]+1):

        X.append(s[y])

    A.append(X)

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

#print(A)

ANS=0

for i in range(2**N):

    n=i

    for j in range(N):

        if n//(2**(N-1-j))==1:

            S[j]=1

        else:

            S[j]=0

        n%=(2**(N-1-j))

    #print(S,i)

    cnt=0

    for a in range(M):

        Y=0

        for b in range(len(A[a])):

            Y+=S[A[a][b]-1]

        if Y%2==P[a]:

            cnt+=1

        

    #print(cnt)

    if cnt==M:

        ANS+=1

print(ANS)

        
N,M=list(map(int,input().split()))

L=[]



for i in range(M):

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

    L.append(m[1:])



#print(L)



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



ans=0



for i in range(2**N):

    sw=[0 for i in range(M)]

    I=i+0

    for j in range(N):

        if I&1==True:

            for k in range(M):

                if j+1 in L[k]:

                    sw[k]+=1

        I=I>>1

    #print(sw)

    cnt=0

    for j in range(M):

        if sw[j]%2==S[j]:

            cnt+=1

    if cnt==M:

        ans+=1

print(ans)
N, M = list(map(int, input().split()))
S = [0 for i in range(N)]
A = []
for x in range(M):
    s = list(map(int, input().split()))
    X = []
    for y in range(1, s[0] + 1):
        X.append(s[y])
    A.append(X)
P = list(map(int, input().split()))
# print(A)
ANS = 0
for i in range(2**N):
    n = i
    for j in range(N):
        if n // (2 ** (N - 1 - j)) == 1:
            S[j] = 1
        else:
            S[j] = 0
        n %= 2 ** (N - 1 - j)
    # print(S,i)
    cnt = 0
    for a in range(M):
        Y = 0
        for b in range(len(A[a])):
            Y += S[A[a][b] - 1]
        if Y % 2 == P[a]:
            cnt += 1
    # print(cnt)
    if cnt == M:
        ANS += 1
print(ANS)

N, M = list(map(int, input().split()))
L = []
for i in range(M):
    m = list(map(int, input().split()))
    L.append(m[1:])
# print(L)
S = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    sw = [0 for i in range(M)]
    I = i + 0
    for j in range(N):
        if I & 1 == True:
            for k in range(M):
                if j + 1 in L[k]:
                    sw[k] += 1
        I = I >> 1
    # print(sw)
    cnt = 0
    for j in range(M):
        if sw[j] % 2 == S[j]:
            cnt += 1
    if cnt == M:
        ans += 1
print(ans)

-S = [0 for i in range(N)] -A = [] -for x in range(M): -    s = list(map(int, input().split())) -    X = [] -    for y in range(1, s[0] + 1): -        X.append(s[y]) -    A.append(X) -P = list(map(int, input().split())) -# print(A) -ANS = 0 +L = [] +for i in range(M): +    m = list(map(int, input().split())) +    L.append(m[1:]) +# print(L) +S = list(map(int, input().split())) +ans = 0 -    n = i +    sw = [0 for i in range(M)] +    I = i + 0 -        if n // (2 ** (N - 1 - j)) == 1: -            S[j] = 1 -        else: -            S[j] = 0 -        n %= 2 ** (N - 1 - j) -    # print(S,i) +        if I & 1 == True: +            for k in range(M): +                if j + 1 in L[k]: +                    sw[k] += 1 +        I = I >> 1 +    # print(sw) -    for a in range(M): -        Y = 0 -        for b in range(len(A[a])): -            Y += S[A[a][b] - 1] -        if Y % 2 == P[a]: +    for j in range(M): +        if sw[j] % 2 == S[j]: -    # print(cnt) -        ANS += 1 -print(ANS) +        ans += 1 +print(ans)