import kotlin.comparisons.compareBy

fun main(args: Array<String>) {
    val lines: MutableList<List<Int>> = mutableListOf()
    while (true) {
        val str = readLine()
        if (str != null) {
            lines.add(str.split(" ").map { Integer.parseInt(it) })
        } else {
            break
        }
    }
    val n = lines[0][0]
    val m = lines[0][1]

    var switchList = (1..n).map { Switch() }
    val pp = lines.last()

    val lightList: MutableList<Light> = mutableListOf()
    (1..m).map {
        val light = Light(oe = pp[it-1])
        val line = lines[it]
        val k = line[0]
        (1..k).map { switchList[line[it]-1] }
                .forEach { it.connected.add(light) }
        lightList.add(light)
    }

    switchList = switchList.sortedWith(compareBy { it.connected.size })

    val case = 2 shl (n - 1)

    var count = 0
    (0 until case).forEach { cn ->
//        println("case: " + cn)
        (0 until n).forEach {
            switchList[it].switchTo((cn shr it) and 1)
        }
        if (lightList.all { it.on() }) count++
    }
    print(count)
}

data class Light(val oe: Int, var count: Int = 0) {
    fun on(): Boolean {
//        println(this)
        return count % 2 == oe
    }
}
data class Switch(val connected: MutableList<Light> = emptyList<Light>().toMutableList(), var state: Int = 0) {
    fun switchTo(state: Int) {
        if (state != this.state) {
            this.state = state
            this.connected.forEach {
                if (state == 0) {
                    it.count--
                } else {
                    it.count++
                }
            }
        }
    }
}
