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 (i <- 0 until n) {
    var count = 0
    val judge = data(i).indices.filter(k => i != k && data(i)(k) == 1)
    if (judge.isEmpty) count = 1
    else {
      val judge2 = judge.filter(j => data(j)(i) == 1 || data(j)(i) == -1)
      if (judge2.nonEmpty) {
        count += 1
        judge2.foreach(_ => count += 1)
      }
    }
    if (count > max) max = count
  }
  println(max)
}