data class Testify(val x: Int, val y: Boolean)
fun main(args: Array<String>) {
    val N = nextInt()
    val A = Array(N) { mutableListOf<Testify>() }
    repeat(N) {
        val a = it
        val n = nextInt()
        repeat(n) {
            val (x, y) = listOfInt()
            A[a].add(Testify(x - 1, y == 1))
        }
    }
    var ans = 0
    var bit = 0
    while (bit < (1 shl N)) {
        var v = BooleanArray(N)
        for (b in 0 until N) {
            v[b] = (bit and (1 shl b)) != 0
        }
        var ok = true
        for (n in 0 until N) {
            if (!v[n]) continue //★
            for (t in A[n]) {
                if (v[t.x] xor t.y) ok = false
            }
        }
        if (ok) ans = Math.max(ans, v.count { it })
        bit += 1
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun printErr(value: Any) = System.err.println(value)
