object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val n  = sc.nextInt
	
	val eis = Seq.fill(n)(Seq.fill(sc.nextInt)((sc.nextInt - 1, sc.nextInt == 1)).toMap).zipWithIndex
	
	println((eis.filter{ case (e, i) => e.toList.forall{ case (x, y) => x != i && !y } }.map(_ => 1) ++
		(2 to n).filter{ eis.combinations(_).exists{ecis =>
				(0 until n) forall { case i =>
					if (ecis.map(_._2) contains i) ecis.forall(_._1.getOrElse(i, true))
					else ecis.map(_._1.get(i)).filter(_ != None).map(_.get).distinct.length < 2
				}
			}
		} ++ Seq(0)).max
	)
}