import java.io.PrintWriter
val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

fun func() {
    val (N, M) = listOfInt()
    var SW = Array<Int>(N, { 0 })
    for (m in 0 until M) {
        val mm = 1 shl m
        val K = listOfInt().drop(1)
        for (k in K) {
            val sw = k - 1;
            SW[sw] = SW[sw] or mm
        }
    }
    var p = 0
    val P = listOfInt()
    P.forEachIndexed { index, i -> p = p or (i shl index)}

    var ans = 0;
    for (k in 0 until (1 shl N)) {
        var t = 0
        for (n in 0 until N) {
            if (((k ushr n) and 1) != 0) t = t xor SW[n]
        }
        if (t == p) ans++
    }
    println(ans);
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) } //{ it.toInt() }
