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

ret = [(bin(n)[2:].zfill(N))[::-1] for n in range(2**N)]

# 入力を保持
kss = []
for i in range(M):
  kss.append(input())
ps = list(map(int, input().split()))

#print(ret)

def test(ret):
  if 0 < sum([int(ret[t-1]) for t in tmp]):
    return sum([int(ret[t-1]) for t in tmp]) % 2 == ps[p_i]
  return False

# 処理
p_i = 0
for ks in kss:
  l = list(map(int, ks.split()))
  tmp = l[1:]
  ret = list(filter(test, ret))
  if ret == None:
    break
  p_i = p_i + 1
#  print(ret)

if ret != None:
  print(len(ret))
else:
  print(0)
