Problem:
Score : 300 points

Problem 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?

Constraints

1 \leq N, M \leq 10

1 \leq k_i \leq N

1 \leq s_{ij} \leq N

s_{ia} \neq s_{ib} (a \neq b)

p_i is 0 or 1.

All values in input are integers.

Input

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

Output

Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.

Sample Input 1

2 2
2 1 2
1 2
0 1

Sample Output 1

1

Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2.

Bulb 2 is lighted when there is an odd number of switches that are "on" among the following: Switch 2.

There are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.

Sample Input 2

2 3
2 1 2
1 1
1 2
0 0 1

Sample Output 2

0

Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2.

Bulb 2 is lighted when there is an even number of switches that are "on" among the following: Switch 1.

Bulb 3 is lighted when there is an odd number of switches that are "on" among the following: Switch 2.

Switch 1 has to be "off" to light Bulb 2 and Switch 2 has to be "on" to light Bulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0.

Sample Input 3

5 2
3 1 2 5
2 2 3
1 0

Sample Output 3

8

Solution in Ruby (2.3.3) (judge verdict: Wrong Answer)

n, m = gets.split(" ").map(&:to_i)
lights = []
m.times do
  lights.push(gets.split(" ").map(&:to_i))
end

ps = gets.split(" ").map(&:to_i)

lights.each do |li|
  li.shift(1)
end
# puts lights

switches = []

10.times do
  switches.push(false)
end

sum = 0
true_count = 0
judge = false
2.times do |index1|
  2.times do |index2|
    2.times do |index3|
      2.times do |index4|
        2.times do |index5|
          2.times do |index6|
            2.times do |index7|
              2.times do |index8|
                2.times do |index9|
                  2.times do |index10|
                    if index1 == 0
                      switches[0] = true
                    else
                      switches[0] = false
                    end
                    if index2 == 0
                      switches[1] = true
                    else
                      switches[1] = false
                    end
                    if index3 == 0
                      switches[2] = true
                    else
                      switches[2] = false
                    end
                    if index4 == 0
                      switches[3] = true
                    else
                      switches[3] = false
                    end
                    if index5 == 0
                      switches[4] = true
                    else
                      switches[4] = false
                    end
                    if index6 == 0
                      switches[5] = true
                    else
                      switches[5] = false
                    end
                    if index7 == 0
                      switches[6] = true
                    else
                      switches[6] = false
                    end
                    if index8 == 0
                      switches[7] = true
                    else
                      switches[7] = false
                    end
                    if index9 == 0
                      switches[8] = true
                    else
                      switches[8] = false
                    end
                    if index10 == 0
                      switches[9] = true
                    else
                      switches[9] = false
                    end
                    lights.each_with_index do |light, l_index|
                      judge = true
                      light.each do |l|
                        if switches[l] == true
                          true_count += 1
                          # puts "plus"
                        end
                      end
                      if true_count % 2 == 0 && ps[l_index] == 1
                        judge = false
                      elsif true_count % 2 == 1 && ps[l_index] == 0
                        judge = false
                      end
                    end
                    if judge == true
                      sum += 1
                    end
                    true_count = 0
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

deduction = 10 - n + 1

puts sum / (2 ** deduction)