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

int_switch_repr = 2**N

light_bulbs_switches = []

for i in range(M):

  k_s = [int(x) for x in input().split()]

  k_i = k_s[0]

  light_bulbs_switches.append(k_s[1:]) # i-th light bulb

P = [int(x) for x in input().split()]  # p_i



ans = 0

for itg in range(int_switch_repr):

  binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill='0', width=N)

  all_on = True

  for lbs_i, p_i in zip(light_bulbs_switches, P):

    is_light_on = sum([1 for sw in lbs_i if binary_switch_repr[int(sw)-1]=='1'])%2 == p_i

    if not is_light_on:

      all_on = False

  if all_on:

    ans+=1



print(ans)
N, M = list(map(int, input().split()))

int_switch_repr = 2**N

light_bulbs_switches = []

for i in range(M):

  k_s = [int(x) for x in input().split()]

  k_i = k_s[0]

  light_bulbs_switches.append(k_s[1:]) # i-th light bulb

P = [int(x) for x in input().split()]  # p_i



ans = 0

for itg in range(int_switch_repr):

  binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill='0', width=N)

  all_on = True

  for lbs_i, p_i in zip(light_bulbs_switches, P):

    is_light_on = sum([1 for sw in lbs_i if binary_switch_repr[int(sw)-1]=='1'])%2 == p_i

    if not is_light_on:

      all_on = False

      break

  if all_on:

    ans+=1



print(ans)
N, M = list(map(int, input().split()))
int_switch_repr = 2**N
light_bulbs_switches = []
for i in range(M):
    k_s = [int(x) for x in input().split()]
    k_i = k_s[0]
    light_bulbs_switches.append(k_s[1:])  # i-th light bulb
P = [int(x) for x in input().split()]  # p_i
ans = 0
for itg in range(int_switch_repr):
    binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill="0", width=N)
    all_on = True
    for lbs_i, p_i in zip(light_bulbs_switches, P):
        is_light_on = (
            sum([1 for sw in lbs_i if binary_switch_repr[int(sw) - 1] == "1"]) % 2
            == p_i
        )
        if not is_light_on:
            all_on = False
    if all_on:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
int_switch_repr = 2**N
light_bulbs_switches = []
for i in range(M):
    k_s = [int(x) for x in input().split()]
    k_i = k_s[0]
    light_bulbs_switches.append(k_s[1:])  # i-th light bulb
P = [int(x) for x in input().split()]  # p_i
ans = 0
for itg in range(int_switch_repr):
    binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill="0", width=N)
    all_on = True
    for lbs_i, p_i in zip(light_bulbs_switches, P):
        is_light_on = (
            sum([1 for sw in lbs_i if binary_switch_repr[int(sw) - 1] == "1"]) % 2
            == p_i
        )
        if not is_light_on:
            all_on = False
            break
    if all_on:
        ans += 1
print(ans)

+            break