import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val input: Array[Map[Int, Int]] = Array.fill(n) {
    Array.fill(sc.nextInt)(sc.nextInt - 1, sc.nextInt).toMap
  }

  var result = 0
  for (i <- 0 until (1 << n)) {

    val digits = i.toString.size
    val str = (0 until (n - digits)).map(_ => "0").mkString
    val c = (str + i.toBinaryString.toInt).reverse
    var isValid = true
    import scala.util.control.Breaks.{break, breakable}
    breakable {
      for (j <- 0 until n) {
        if (((i >> j) & 1) == 1) {
          val ok = input(j).forall { pair => c(pair._1).asDigit == pair._2 }
          if (!ok) {
            isValid = false
            break
          }
        }
      }
    }
    if (isValid) {
      result = Math.max(result, c.count(c => c.equals('1')))
    }

  }

  println(result)
}
