n, m = map(int, input().split())
s = []

def on_off(upper_index, input_list): #index未満を全て切り替える
  for l in range(upper_index):
    if input_list[l] == 0:
      input_list[l] = 1
    elif input_list[l] == 1:
      input_list[l] = 0
  
  
def judge(switch_list): #1-m全ての電球が点灯するか判定. 正しければ1を返す
  count_list = [0] * m
  for k_index in range(m):
    count = 0
    for s_index in range(n):
      if switch_list[s_index] in s[k_index][1:] and switch_list[s_index] == 1:
        count += 1
    if count != 0 and count % 2 == p[k_index]:
      count_list[k_index] = 1
    else:
      break
  if 0 in count_list:
    return 0
  else:
    return 1
   
for i in range(m):
  s.append(list((int(i) for i in input().split())))
p = [int(i) for i in input().split()]

s_switch = [0] * n
count_patern = 0
i = 0
while i < n:
  count_patern += judge(s_switch)
  count_temp = 0
  for j in range(1, i+1):
    count_temp += s_switch[j-1]
    if count_temp < j:
      on_off(j, s_switch)
      if s_switch[i-1] == 1:
        i += 1
      break
print(count_patern)