import util.control.Breaks._

object Main extends App {
  val n = io.StdIn.readLine().toInt
  val testimony = 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)
      testimony(i)(x-1) = y
    }
  }

  for (b <- 0 until 1 << n) {
    breakable {
      val honest = for (i <- 0 until n; if (b & (1 << i)) != 0) yield i
      for (a <- honest) {
        for (b <- honest; if testimony(a)(b) == 0 || testimony(b)(a) == 0) break()
        testimony(a).indices.withFilter(testimony(a)(_) == 1).foreach(b => if (testimony(b)(a) == 0) break())
      }
      val count = honest.length
      if (max < count) max = count
    }
  }

  println(max)
}