
import scala.io.StdIn._
object Main extends App {

  val n: Int = readInt()
  val a = Array.fill(n)(0)
  val testimoniesPerPerson: Array[List[(Int,Int)]] = Array.fill(n)(Nil)
  for (i <- 0 until n) {
    a(i) = readInt
    (0 until a(i)).foreach{ _ =>
      testimoniesPerPerson(i) = (readLine.split(" ").map{_.toInt} match {
        case x => (x(0)-1,x(1))}) :: testimoniesPerPerson(i)
    }
  }


  def solve(): Long = {
    (0 until (1 << n)).foldLeft(0L) { case (acc, i) =>
      val isAllTrue: Boolean = (0 until i).collect { case j if isBitOn(i, j) =>
        testimoniesPerPerson(j).forall { case (x, y) =>
          y ==  ((i >> x) & 1)
        }
      }.forall(identity)
      if(isAllTrue) Math.max(acc, countHonest(i)) else acc
    }
  }

  def isBitOn(bit: Long, digit: Long): Boolean =
    ((bit >> digit) & 1) != 0

  def countHonest(bit: Long): Long =
    (0 until n).foldLeft(0L) { case (acc, digit) =>
      if(isBitOn(bit, digit)) acc + 1 else acc
    }


  println(solve())

}
