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

sum = 0
isAffectedSwitch=[[False for _ in range(n)] for _ in range(m)]
for i in range(m):
    for j in range(1,s[i][0]+1):
        isAffectedSwitch[i][s[i][j]-1]=True

C = []
for i in range(N):
    B = 0
    for j in range(M):
        if isAffectedSwitch[j][i] = True:
            B += 2**(M-j-1)
    C.append(B)

for i in range(2**N):
    A = 0
    for j in range(N):
        if (i >> j):
            A = A^C[j]
    if A == p:
        sum += 1
        
print(sum)