
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 peopleList: Seq[Boolean] = (0 until i).collect {
//        case j if isBitOn(i, j) => isHonestPerson(j, i)
//      }
      val isValid: Boolean = (0 until i)
        .filter(j => isBitOn(i, j))
        .forall(j => isHonestPerson(j, i))

      if(isValid) Math.max(acc, countHonest(i)) else acc
    }
  }

  def isHonestPerson(personIndex: Int, bit: Int): Boolean =
    testimoniesPerPerson(personIndex).forall { case (x, y) =>
      y == ((bit >> x) & 1)
    }

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

  def countHonest(bit: Int): Int=
    Integer.bitCount(bit)


  println(solve())

}
