import java.lang.Math

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

    for (i in 0 until n) {
        val a = readLine()!!.toInt()
        s.add(mutableMapOf<Int, Int>())
        for (k in 0 until a) {
            val (x, y)  =readLine()!!.split(" ").map{it.toInt()}
            s[i].put(x-1, y)
        }
    }
    // println(s.lastIndex)

    var ans = -1
    for (i in 0 until (1 shl n)) { // 2^n回の繰り返し
        // println("i: ${i}")
        var cnt = 0
        var flag = true
        for (k in 0 until n) {
            if ((i and (1 shl k)) != 0) {
                cnt++
                for (key in s[k].keys) {
                    if (!(s[k][key] == 1 && (i and (1 shl key)) != 0) && !(s[k][key] == 0 && (i.inv() and (1 shl key)) != 0)) {flag = false}

                    if (!flag) break
                }
            }

            if (!flag) break
        }

        if (flag) {
            ans = Math.max(ans, cnt)
        }
    }

    println(ans)
}
