fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val aa = 1.until(n + 1).map {
        val a = readLine()?.toInt() ?: return
        A(
            it,
            0.until(a).map {
                val (x, y) = readLine()?.split(" ")?.map(String::toInt) ?: return
                Testimony(x, y == 0)
            }
        )
    }
    val candidates = mutableListOf<BooleanArray>()
    generateCandidates(booleanArrayOf(), n, 0, candidates)

    val count = candidates.map { liars ->
        if (verify(aa, liars)) {
            liars.count { !it }
        } else {
            0
        }
    }.max()
    println(count.toString())
}

data class Testimony(val number: Int, val liar: Boolean)
data class A(
    val number: Int,
    val testimony: List<Testimony>
)

fun verify(aa: List<A>, liars: BooleanArray): Boolean {
    aa.flatMap {
        val liar = liars[it.number - 1]
        if (liar) {
            emptyList()
        } else {
            it.testimony
        }
    }.forEach {
        if (liars[it.number - 1] != it.liar) {
            return false
        }
    }
    return true
}

tailrec fun generateCandidates(array: BooleanArray, n: Int, index: Int, candidates: MutableList<BooleanArray>) {
    if (index == n) {
        candidates.add(array)
    } else {
        generateCandidates(array + booleanArrayOf(true), n, index + 1, candidates)
        generateCandidates(array + booleanArrayOf(false), n, index + 1, candidates)
    }
}
