fun main(args : Array<String>) {
    val (N ,M) = readLine()!!.split(" ").map { it.toInt() }
    val S = mutableListOf<List<Int>>()
    (1..M).forEach {
        val kAndS = readLine()!!.split(" ").map { it.toInt() }
        S.add(kAndS.subList(1, kAndS.size))
    }
    val P = readLine()!!.split(" ").map { it.toInt() }

    val allConbinations = Math.pow(2.toDouble(), N.toDouble()).toInt()

    var answer = 0
    // O(2^N)
    for (bits in 1..allConbinations) {
        // O(N)
        val switchFlags = mutableListOf<Boolean>()
        for (i in 0..(N - 1)) {
            val iThSwitchOn = isBitSet(bits, i)
            switchFlags.add(iThSwitchOn)
        }

        var allFlashed = true
        // o(M)
        S.forEachIndexed { index, s ->
            if (allFlashed) {
                val p = P[index]
                var onCount = 0
                // O(K)
                s.forEach { switchIndex ->
                    if (switchFlags[switchIndex - 1]) {
                        onCount++
                    }
                }
                if (onCount.mod(2) != p) {
                    allFlashed = false
                }
            }
        }

        if (allFlashed) {
            answer++
        }
    }

    println(answer)
}
fun isBitSet(bit: Int, index: Int) : Boolean {
    return bit.shr(index).and(1) == 1
}