fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }


    val connectedLump = mutableListOf<MutableList<Int>>()
    for (i in 0 until n) {
        connectedLump.add(mutableListOf())
    }



    for (i in 0 until m){
        val inputs = readLine()!!.split(" ").map { it.toInt() }
        for (j in 1 until inputs.size) {
            connectedLump[inputs[j]-1].add(i)
        }
    }

    val condition = readLine()!!.split(" ").map { it.toInt() }

    var countAns = 0
    val lumpStatus = IntArray(m){0}.toMutableList()

    fun updateStatus(count: Int, mem: MutableList<Int>) {

        if (count == n){
            for(i in 0 until mem.size) {
                if (mem[i]%2 != condition[i]) {
                    return
                }
            }
            countAns += 1
            return
        }

        // スイッチを入れる場合
        val memTemp = mem.toMutableList()
        for (l in connectedLump[count]){
            memTemp[l] += 1
        }
        updateStatus(count+1, memTemp)

        // スイッチを入れない場合
        val memTempOff = mem.toMutableList()
        updateStatus(count+1, memTempOff)
    }

    updateStatus(0, lumpStatus)

    println(countAns)
}