import java.util.*

fun add1(len: Int, arr: Array<Int>): Array<Int> {
    val ans = Array<Int>(len, { 0 })
    var go = true
    for (i in 0..len-1) {
        if (go) {
            if (arr[i] == 0) {
                ans[i] = 1
                go = false
            } else {
                if (i == len-1) {
                    ans[i] = 2
                } else {
                    ans[i] = 0
                }
            }
        } else {
            ans[i] = arr[i]
        }
    }
    return ans
}

fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val m = cin.nextInt()
    val connected = Array<MutableList<Int>>(n, { mutableListOf() })
    for (i in 0..m-1) {
        val k = cin.nextInt()
        for (j in 0..k-1) {
            val t = cin.nextInt() - 1
            connected[t].add(i)
        }
    }

    val p_arr = Array<Int>(m, { cin.nextInt() })

    var onoff = Array<Int>(n, { 0 })
    var ans = 0
    while (true) {
        val p_test_arr = Array<Int>(m, { 0 })
        for (i in 0..n-1) {
            if (onoff[i] == 1) {
                for (ele in connected[i]) {
                    p_test_arr[ele] += 1
                }
            }
        }
        for (i in 0..m-1) {
            if (p_test_arr[i] % 2 != p_arr[i]) {
                break
            }
            if (i == m-1) {
                ans += 1
            }
        }
        onoff = add1(n, onoff)
        if (onoff[n-1] == 2) {
            break
        }
    }
    println(ans)
}