output_description: Print the number of combinations of "on" and "off" states of the switches that
  light all the bulbs.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      k_1 s_{11} s_{12} ... s_{1k_1}
      :
      k_M s_{M1} s_{M2} ... s_{Mk_M}
      p_1 p_2 ... p_M
attempt: import copy
  
  
  class Lamp:
  
      def __init__(self, id, connected_switches):
          self.id = id
          self.on_number = 0
          self.connected_switches = connected_switches
          self.connected_number = len(connected_switches)
  
      def set_on_number(self, on_number):
          self.on_number = on_number
  
  
  inp = input()
  st = inp.split()
  n = int(st[0])
  m = int(st[1])
  lamp_dictionary = {}
  lamp_list = []
  for i in range(m):
      inp = input()
      st = inp.split()
      k = int(st[0])
      connected_switches = []
      for j in range(k):
          s = int(st[j + 1])
          connected_switches.append(s)
      lamp_list.append(Lamp(i + 1, connected_switches))
  # input p
  inp = input()
  st = inp.split()
  for i in range(m):
      p = int(st[i])
      lamp_c = lamp_list[i]
      lamp_c.set_on_number(p)
      k = lamp_c.connected_number
      if k in lamp_dictionary:
          lamps = lamp_dictionary[k]
          lamps.append(lamp_c)
      else:
          lamp_dictionary[k] = [lamp_c]
  
  lamp_sorted_list = sorted(lamp_dictionary.keys())  # つながっているスイッチの少ない順
  lamps_list = []  # 小さい順に並べたlampのりすと
  for connected_number in lamp_sorted_list:
      lamps = lamp_dictionary[connected_number]
      for lamp in lamps:
          lamps_list.append(lamp)
  # スウイッチを決定していく
  switch_list = [0 for _ in range(n + 1)]  # 0:not decided 1:on 2:off
  
  
  def decide_switch(i):
      # 可能な数を返す
      if i == len(lamps_list):
          return 1
      lamp = lamps_list[i]
      able_decide_switches = []
      on_count = 0
      for switch in lamp.connected_switches:
          if switch_list[switch] == 0:
              able_decide_switches.append(switch)
          elif switch_list[switch] == 1:
              on_count += 1
      # 少なくとも可能なスイッチのパターが一つあれば次のランプを調べる
      p = lamp.on_number
      if not able_decide_switches:
          if on_count % 2 == p:
              return decide_switch(i + 1)
          else:
              return 0
      else:
          # スイッチを変えられる.変えられる可能性すべてを調べる
          changing_list = make_list([], 1, len(able_decide_switches))
          total_able_change_count = 0
          if not changing_list:
              print("")
          for chang in changing_list:
              count = on_count
              for num in chang:
                  count += num
              if count % 2 == p:
                  # 次のランプを調べる
                  for inde, num in enumerate(chang):
                      v = num
                      if num == 0:
                          v = 2
                      switch_list[able_decide_switches[inde]] = v
                  total_able_change_count += decide_switch(i + 1)
                  # すいっちを0にもどす
                  for inde, num in enumerate(chang):
                      switch_list[able_decide_switches[inde]] = 0
          return total_able_change_count
  
  
  def make_list(l, i, max_n):
      ol = copy.deepcopy(l)
      il = copy.deepcopy(l)
      ol.append(0)
      il.append(1)
      if i == max_n:
          return [ol, il]
      ooo = make_list(ol, i + 1, max_n)
      iii = make_list(il, i + 1, max_n)
      for ii in iii:
          ooo.append(ii)
      return ooo
      # return make_list(ol, i+1, max_n).extend(make_list(il, i+1, max_n))
  
  
  ans = decide_switch(0)
  print(int(ans / 2))
  
problem_description: Statement
  
  We have N switches with "on" and "off" state, and M bulbs. The switches are
  numbered 1 to N, and the bulbs are numbered 1 to M.
  
  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}.
  It is lighted when the number of switches that are "on" among these switches
  is congruent to p_i modulo 2.
  
  How many combinations of "on" and "off" states of the switches light all the
  bulbs?
samples: [{"input": "2 2\n    2 1 2\n    1 2\n    0 1", "output": "1\n    \n\n  * Bulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n  * Bulb 2 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nThere are four possible combinations of states of (Switch 1, Switch 2): (on,\non), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all\nthe bulbs, so we should print 1.\n\n* * *"}, {"input": "2 3\n    2 1 2\n    1 1\n    1 2\n    0 0 1", "output": "0\n    \n\n  * Bulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n  * Bulb 2 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1.\n  * Bulb 3 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nSwitch 1 has to be \"off\" to light Bulb 2 and Switch 2 has to be \"on\" to light\nBulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations\nof states of the switches that light all the bulbs, so we should print 0.\n\n* * *"}, {"input": "5 2\n    3 1 2 5\n    2 2 3\n    1 0", "output": "8"}]