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

  val n: Int = readInt()
  val testimoniesPerPerson: Seq[Seq[(Int, Int)]] = (1 to n).map { _ =>
    val numOfTestimonies = readInt()
    val testimonies: Seq[(Int, Int)] = Seq.fill(numOfTestimonies) {
      val testimony: Array[Int] = readLine().split(" ").map(_.toInt)
      (testimony(0) - 1, testimony(1)) // Modify to 0 origin
    }
    testimonies
  }


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

  def isValid(x: Int, y: Int, bit: Int): Boolean = {
    { y == 1 && isBitOn(bit, x) } || { y == 0 && !isBitOn(bit, x) }
  }

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

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


  println(solve())

}
