import java.util.*
fun main(args:Array<String>) {
    val (N,M) = readLine()!!.split(" ").map(String::toInt)
    val switch_pattern = (1..M).map {
        val line = readLine()!!.split(" ").map(String::toInt)
        val k = line[0]
        assert(k == line.size - 1 )
        line.slice(1..k)
    }
    val pm = readLine()!!.split(" ").map(String::toInt)
    assert(pm.size == M)
    var count = 0
    var pattern_integer = 0 
    while(pattern_integer < 1 shl N) {
        val ok_pattern = (0.until(M)).all { index ->
            val x = switch_pattern[index].filter {s -> ((1 shl (s-1)) and pattern_integer) > 0}.size
            x % 2 == pm[index]
        }
        count += if(ok_pattern) {1} else {0}
        pattern_integer = pattern_integer + 1
    }
    println(count)
}