n,m = (int(x) for x in input().split())
swi = []
for i in range(m):
  l = [int(x) for x in input().split()]
  t = 0
  for i in range(1,len(l)):
    t += 1 << (l[i]-1)
  swi.append(t)
ppp = [int(x) for x in input().split()]

ans = 0
for i in range(1 << n):
  for s, p in zip(swi,ppp):
    t = i & s
    c = bin(t).count("1") % 2
    if c != p:
      break
  else:
    print(i)
    ans += 1
print(ans)