n,m=map(int,input().split())
binlist=[]
for iii in range(m):
  ks=[int(_) for _ in input().split()]
  k=ks[0]
  s=ks[1:]
  binn=0
  for kkk in range(k):
    binn+=2**(s[kkk]-1)
  binlist.append(binn)
q=[int(_) for _ in input().split()]
cnt=0
for iii in range(2**n):
  res=[]
  for jjj in binlist:
    res.append(bin(jjj & iii).count("1")%2)
  if res==q:
    cnt+=1

    print(cnt)