fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = Array(n){ mutableListOf<Pair<Int, Int>>() }

    repeat(n) { aIdx ->
        val a = readLine()!!.toInt()
        repeat(a) {
            val (x, y) = readLine()!!.split(" ").map { it.toInt() }
            aa[aIdx].add(Pair(x, y))
        }
    }

    var max = 0
    for (i in 0 until 1.shl(n)) {
        var failed = false

        inner@for (j in aa.indices) {
            val shouldSkip = ((i.shr(j) and 1) == 0)
            if (shouldSkip) continue@inner

            for (k in aa[j]) {
                val target = (i.shr(k.first-1) and 1)
                if (target != k.second) {
                    failed = true
                    break@inner
                }
            }
        }

        if (!failed) {
            max = Math.max(max, Integer.bitCount(i))
        }
    }

    println(max)
}