object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val n  = sc.nextInt
	
	val es = Seq.fill(n)(Seq.fill(sc.nextInt)((sc.nextInt - 1, sc.nextInt == 1)).toMap)
	
	println((es.zipWithIndex.filter{case (e, i) => e.toList.forall{case (x, y) => x != i && !y}}.map(_ => 1) ++
		(2 to n).filter{i: Int =>
			es.combinations(i).exists(_.combinations(2).forall{case Seq(e1, e2) => 
				e1.foldLeft(true) {case (z, (x, y)) => z && e2.get(x).map(y == _).getOrElse(true)} &&
				e2.foldLeft(true) {case (z, (x, y)) => z && e1.get(x).map(y == _).getOrElse(true)}
		})
	} ++ Seq(0)).max)
}