object Main extends App {
  val n = readInt
  val a = Array.fill(n)(0)
  val xy:Array[List[(Int,Int)]] = Array.fill(n)(Nil)
  for (i <- 0 until n) {
    a(i) = readInt
    (0 until a(i)).foreach{ _ =>
      xy(i) = (readLine.split(" ").map{_.toInt} match {case x => (x(0)-1,x(1))}) :: xy(i)
    }
  }
  
  def solve(i:Int,honestList:List[Int]):Int = {
    if (i == n) {
      val h = honestList.reverse.toArray
      val ok = (
        for (i <- 0 until n) yield {
          if (h(i)==1) xy(i).map{case (x,y) => h(x) == y}.forall{_ == true} else true
        }).forall{_ == true}
      if (ok) h.sum else 0
    }
    else {
      scala.math.max(solve(i+1,0::honestList),solve(i+1,1::honestList))
    }
  }
  
  println(solve(0,Nil))
}