case class Test(index: Int, test: Boolean)

object Main extends App {
  main()

  def main() {
    val n = readLine().toInt
    val as = for {
      i <- Range(0, n)
    } yield {
      val ai = readLine().toInt
      for {
        ii <- Range(0, ai)
      } yield {
        val xy = readLine().split(' ')
        Test(xy(0).toInt - 1, xy(1).toInt > 0)
      }
    }
    val loop = for {
      dec <- Range(0, math.pow(2, n).toInt).reverse
    } yield {
      val bin = dec.toBinaryString.reverse.padTo(n, '0').reverse
      val bs = bin.map(_ == '1')
      if (as.zip(bs).filter(_._2).foldLeft(true)((a, b) => a && b._1.foldLeft(true)((c, d) => c && d.test == bs(d.index)))) bs.filter(_ == true).size
      else 0
    }
    println(loop.max)
  }
}
