n, m = gets.split(' ').map(&:to_i)

Switch = Struct.new(:state) do
  def turn_on
    self.state = 'on'
  end

  def turn_off
    self.state = 'off'
  end

  def on?
    state == 'on'
  end
end

switches = n.times.each_with_object({}) do |i, hash|
  hash[i+1] = Switch.new
end

Light = Struct.new(:sw_ids, :p, :switches) do
  def on?
    sw_ids.count { |sw_id| switches[sw_id].on? } % 2 == p
  end
end

lights = []
m.times do |i|
  inputs = gets.split(' ').map(&:to_i)
  sw_ids = inputs[1..inputs[0]]
  lights << Light.new(sw_ids, nil, switches)
end

gets.split(' ').map(&:to_i).each_with_index do |p, i|
  lights[i].p = p
end

patterns = 0
b = 2**n - 1
loop do
  bits = b.to_s(2)
  order = sprintf("%0#{n}d", bits)
  order.split('').each_with_index do |o, i|
    sw = switches[i+1]
    if o == "1"
      sw.turn_on
    else
      sw.turn_off
    end
  end

  if lights.all?(&:on?)
    patterns += 1
  end

  if b == 0
    break
  end
  b -= 1
end

print patterns
