import java.lang.Integer.bitCount
import kotlin.math.max

fun main(args: Array<String>) {
    val n = readInt()
    val g = Array(15) { Array(15) { -1 } }
    for (i in 0 until n) {
        val m = readInt()
        repeat(m) {
            var (a, x) = readIntList()
            a--
            g[i][a] = x
        }
    }
    var ans = 0
    for (i in 0 until (1 shl n)) {
        val d = MutableList(n) { 0 }
        for (j in 0 until n) {
            // j番目のビットが立っていたら
            if ((i shr j) and 1 == 1) d[j] = 1
        }
        var ok = true
        for (j in 0 until n) {
            // d[j]は正直者と仮定
            if (d[j] == 1) {
                for (k in 0 until n) {
                    if (g[j][k] == -1) continue
                    // 仮定と証言に矛盾
                    if (g[j][k] != d[k]) ok = false
                }
            }
        }
        if (ok) ans = max(ans, bitCount(i))
    }
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)