import java.io.{BufferedReader, InputStreamReader}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt

    val evs =
      (0 until n).map { _ =>
        val a = in.readLine().toInt
        (0 until a).map { _ =>
          in.readLine().split("\\s+").map(_.toInt) match {
            case Array(x, y) => Array(x - 1, y)
          }
        }
      }

    System.out.println(
      (0 until n).map { i =>
        val honests = new ArrayBuffer[Int]()
        val unkinds = new ArrayBuffer[Int]()

        honests += i

        val honestsQueue = new mutable.Queue[Int]()
        honestsQueue += i

        while (honestsQueue.nonEmpty) {
          val honest = honestsQueue.dequeue()
          evs(honest).foreach { ev =>
            if (ev(1) == 1) {
              if (honests.indexOf(ev(0)) == -1) {
                honests += ev(0)
                honestsQueue += ev(0)
              }
            } else {
              unkinds += ev(0)
            }
          }
        }

        if(honests.intersect(unkinds).nonEmpty) {
          0
        } else {
          honests.size
        }
      }.max
    )
  }
}
