
import java.util.Scanner

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
//  }
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val testimoniesPerPerson: Array[Map[Int, Boolean]] = Array.fill(n){
    Array.fill(sc.nextInt)(sc.nextInt - 1 -> (sc.nextInt == 1)).toMap
  }


//  def solve(): Int = {
//    val valids = (0 until (1 << n)).map{ i =>
//      val valid = (0 until n)
//        .filter{j => isBitOn(i, j)}
//        .forall{j => isHonestPerson(j, i)}
//      if (valid) countHonest(i) else 0
//    }
//    valids.max
//  }

  def solve(): Int = {
    (1 until (1 << n)).map { i =>
      val isValid: Boolean = (0 until i)
        .filter(j => isBitOn(i, j))
        .forall(j => isHonestPerson(j, i))

      if(isValid) countHonest(i) else 0
    }.max
  }

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

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

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


  println(solve())

}
