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 {
      var count = 0
      for (i <- 0 until n; if (b & (1 << i)) != 0) {
        testimony(i).indices.withFilter(testimony(i)(_) != -1).foreach {j =>
          val x = (1 << j) & b
          if (testimony(i)(j) == 1 && x == 0) break()
          if (testimony(i)(j) == 0 && x != 0) break()
          count += 1
        }
      }
      if (max < count) max = count
    }
  }

  println(max)
}