fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val axy = Array(N) {
        val a = readLine()!!.toInt()
        Array(a) {
            readLine()!!.split(" ").map(String::toInt).let { it[0] to it[1] }
        }
    }

    var ans = 0

    for (bits in 0 until (1 shl N)) {

        var ok = true
        for ((i, xy) in axy.withIndex()) {
            if ((bits shr i and 1) == 0) {
                continue
            }

            for ((x, y) in xy) {
                if ((((bits shr (x - 1)) and 1) xor y) == 1) {
                    ok = false
                    break
                }
            }
        }
        if (ok) {
            ans = Math.max(ans, Integer.toBinaryString(bits).count { it == '1' })
        }
    }
    println(ans)

}