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) {
  val honest = data(i).indices.filter(data(i)(_) == 1)
  var count = 1
  breakable {
   for (j <- honest) {
    if (data(j)(i) == 0) break()
    else for (k <- honest) {
     if (data(j)(k) == 0 || data(k)(j) == 0) break()
     count += 1
    }
   }
   if (max < count) max = count
  }
 }
 println(max)
}