import itertools

N,M = map(int, input().split())
all_lst = []
for i in range(M):
  lst = list(map(int, input().split()))
  all_lst.append(lst[1:])

lst_p = list(map(int, input().split()))

l = [0, 1]
on_off = list(itertools.product(l, repeat=N))

for idx,i in enumerate(on_off):
  ans_lst = []
  for j in range(M):
    sum = 0
    for k in all_lst[j]:
      sum += i[k-1]
    ans_lst.append(sum % 2)
  if(ans_lst == lst_p):
    print(1)
    break
  if ((idx+1) == len(on_off)):
    print(0)
