import util.control.Breaks._

object Main extends App {
  val n = io.StdIn.readLine().toInt
  val data = Array.fill(n)(Array.fill(n)(-1))
  var max = 0

  for (i <- 0 until n) {
    val a = io.StdIn.readLine().toInt
    for (_ <- 0 until a) {
      val Array(x, y) = io.StdIn.readLine().split(' ').map(_.toInt)
      data(i)(x-1) = y
    }
  }

  for (b <- 1 to 1 << (n-1)) {
    var count = 0
    breakable {
      for (i <- 0 until n; if (b & (1 << i)) != 0) {
        count += 1
        data(i).indices.foreach(j => if (data(i)(j) == 1 && data(j)(i) == 0) break())
      }
      if (max < count) max = count
    }
  }
  println(max)
}