fun main(args: Array<String>) {
  val N = readInt()
  val XY = (1..N).map {
    val A = readInt()
    (1..A).map { readInts() }
  }

  var max = 0
  for (i in 0 until N) {
    var TFN = arrayOfNulls<Boolean>(N)
    for (i in 0 until i) TFN[i] = false

    fun assume(n: Int, tf: Boolean): Boolean {
      if (TFN[n] != null) {
        return TFN[n] == tf
      }
      TFN[n] = tf
      if (tf) {
        XY[n].forEach {
          val x = it[0]
          val y = it[1] == 1
          if (!assume(x - 1, y)) return false
        }
      }
      return true
    }
    for (j in i until N) {
      val tmp = TFN.copyOf()
      if (assume(j, true)) {
        continue
      }
      TFN = tmp
      assume(j, false)
    }
    val sum = TFN.count { it == true }
    max = Math.max(max, sum)
  }

  println(max)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(' ')
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
