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

#ks[i][0]がk_i

ks = [[int(i) for i in input().split()]for i in range(M)]

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

ans=0

for i in range(2**N):

    flag=0

    #Onoff[i]=0はスイッチiのOFFを、=1はONを表す

    OnOff = [0]*N

    for j in range(N):

        if (i>>j) & 1:

            OnOff[j]=1

    

    for j in range(M):

        count=0

        for l in range(1,len(ks[j])):

            if(OnOff[ks[j][l]-1]==1):

                count+=1

        if(p[j]==0 and count%2==0):

            flag+=1

        elif(p[j]==1 and count%2==1):

            flag+=1

        else:

            pass

    

    if(flag==len(p)):

        ans+=1

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

#ks[i][0]がk_i

ks = [[int(i) for i in input().split()]for i in range(M)]

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

ans=0

for i in range(2**N):

    flag=0

    #Onoff[i]=0はスイッチiのOFFを、=1はONを表す

    OnOff = [0]*N

    for j in range(N):

        if (i>>j) & 1:

            OnOff[j]=1

    

    for j in range(M):

        count=0

        for l in range(1,len(ks[j])):

            if(OnOff[ks[j][l]-1]==1):#-1に注意（スイッチxはOnOff[x-1]に対応）

                count+=1

        if(p[j]==0 and count%2==0):

            flag+=1

        elif(p[j]==1 and count%2==1):

            flag+=1

        else:

            pass

    #全ての電球が点くならばansに+1

    if(flag==len(p)):

        ans+=1

print(ans)
N, M = list(map(int, input().split()))
# ks[i][0]がk_i
ks = [[int(i) for i in input().split()] for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    flag = 0
    # Onoff[i]=0はスイッチiのOFFを、=1はONを表す
    OnOff = [0] * N
    for j in range(N):
        if (i >> j) & 1:
            OnOff[j] = 1
    for j in range(M):
        count = 0
        for l in range(1, len(ks[j])):
            if OnOff[ks[j][l] - 1] == 1:
                count += 1
        if p[j] == 0 and count % 2 == 0:
            flag += 1
        elif p[j] == 1 and count % 2 == 1:
            flag += 1
        else:
            pass
    if flag == len(p):
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
# ks[i][0]がk_i
ks = [[int(i) for i in input().split()] for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    flag = 0
    # Onoff[i]=0はスイッチiのOFFを、=1はONを表す
    OnOff = [0] * N
    for j in range(N):
        if (i >> j) & 1:
            OnOff[j] = 1
    for j in range(M):
        count = 0
        for l in range(1, len(ks[j])):
            if OnOff[ks[j][l] - 1] == 1:  # -1に注意（スイッチxはOnOff[x-1]に対応）
                count += 1
        if p[j] == 0 and count % 2 == 0:
            flag += 1
        elif p[j] == 1 and count % 2 == 1:
            flag += 1
        else:
            pass
    # 全ての電球が点くならばansに+1
    if flag == len(p):
        ans += 1
print(ans)

-            if OnOff[ks[j][l] - 1] == 1: +            if OnOff[ks[j][l] - 1] == 1:  # -1に注意（スイッチxはOnOff[x-1]に対応） +    # 全ての電球が点くならばansに+1