N, M = [int(s) for s in input().split()]
light = []
for i in range(M):
  tmp = [int(s) for s in input().split()]
  light.append([1 if j+1 in tmp[1:] else 0 for j in range(N)])
Plist = [int(s) for s in input().split()]
count = 0
for i in range(2**N):
  num = list(bin(i))
  switch = [num[-(j+1)] for j in range(len(num)-2)]
  if len(switch) < N:
    switch.extend(['0' for j in range(N-len(switch))])
  switch = [int(s) for s in switch]
  on = [0 for j in range(M)]
  for j in range(M):
    answer = [light[j][k]*switch[k] for k in range(N)]
    if sum(answer)//2 == Plist[j]  and sum(answer) > 0:
      on[j] = 1
  if sum(on) == len(on):
    count += 1
print(count)