fun main(args :Array<String>) {
    val n = readInteger()
    val testimonyMap = hashMapOf<Int, Map<Int, Int>>()
    for (i in 1..n) {
        val a = readInteger()
        val testimony = hashMapOf<Int, Int>()
        for (j in 0 until a) {
            val (x, y) = readIntegerList()
            testimony[x] = y
        }
        testimonyMap[i] = testimony
    }

    var ans = 0
    for (i in 0 until (1 shl n)) {
        var shouldCount = true
        for (j in 0 until n) {
            if (((i shr j) and 1) == 1) {
                val testimony = testimonyMap[j + 1]
                val falseList = testimony!!
                    .entries
                    .filter {
                        val tmp = (i shr (it.key - 1)) and 1
                        tmp != it.value
                    }

                if (falseList.isNotEmpty()) {
                    shouldCount = false
                    break
                }
            }
        }

        if (shouldCount) {
            var count = 0
            for (k in 0 until n) {
                // print(((i shr k) and 1))
                if (((i shr k) and 1) == 1) {
                    count++
                }
            }
            ans = Math.max(ans, count)
            // println()
        }
    }

    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
