fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val a = (1 .. n).map{
        (1 .. readLine()!!.toInt()).map{readLine()!!.split(" ").map{it.toInt()}}
    }
    var ans = 0
    for(i in 0 until (1 shl n)){
        var cnt = 0
        var ok = true
        var b = BooleanArray(n)
        for(j in 0 until n){
            if((i shr j) and 1 == 1){
                b[j] = true
                cnt++
            }
        }
        for(j in 0 until n){
            if(b[j]){
                for(k in 0 until a[j].size){
                    if((a[j][k][1] == 1 && b[a[j][k][0] - 1] == false) || (a[j][k][1] == 0 && b[a[j][k][0] - 1] == true)){
                        ok = false
                    }
                }
            }
        }
        if(ok) ans = Math.max(ans, cnt)
    }
    println(ans)
}