fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val testimony = Array(N) { mutableListOf<Pair<Int, Boolean>>() }
    
    for (i in 0 until N) {
        val A = readInputLine().toInt()
        for (j in 0 until A) {
            val (x, y) = readInputLine().split(" ").map { it.toInt() }
            testimony[i].add(Pair(x - 1, y == 1))
        }
    }
    
    var ans = 0
    
    for (i in 0 until pow2(N)) {
        var ok = true
        for (j in 0 until N) {
            if ((i shr j) % 2 == 0) {
                continue
            }
            for (t in testimony[j]) {
                if ((i shr t.first) % 2 == 1 != t.second) {
                    ok = false
                    break
                }
            }
            if (!ok) {
                break
            }
        }
        if (ok) {
            var tmp = 0
            for (j in 0 until N) {
                if ((i shr j) % 2 == 1) {
                    tmp++
                }
            }
            if (tmp > ans) {
                ans = tmp
            }
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}

fun pow2(x: Int): Int {
    var ret = 1
    for (i in 0 until x) {
        ret *= 2
    }
    return ret
}
