fun main(args: Array<String>) {
    abc147c()
}

private fun bits(x: Int): Int {
    var ret = 1
    repeat(x) { ret *= 2 }
    return ret - 1
}

fun abc147c() {
    val n = readLine()!!.toInt()
    val xyList = mutableListOf<List<Pair<Int, Boolean>>>()
    (1..n).forEach { i ->
        val num = readLine()!!.toInt()
        xyList.add((1..num).map { readLine()!!.split(' ').map { it.toInt() } }
            .map { Pair(it[0] - 1, it[1] == 1) })
    }

    var answer = 0
    for (i in 0..bits(n)) {
        val list = BooleanArray(n)
        (0 until n).forEach {
            list[it] = (i shr it) % 2 == 0
        }

        val all = xyList.withIndex().all { iv ->
            val youHonest = list[iv.index]
            iv.value.all {
                val (he, heHonest) = it
                 if (youHonest)list[he] ==  heHonest else true
            }
        }

        if (all) {
            answer = Math.max(answer, list.count { it })
        }
    }

    println(answer)
}
