object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val eis = Seq.fill(sc.nextInt)(Seq.fill(sc.nextInt)((sc.nextInt - 1, sc.nextInt))).zipWithIndex
	
	println((0 until (1 << eis.length)).filter { c =>
		eis.filter {case (e, i) => (c >> i & 1) == 1} forall {_._1 forall {case (x, y) => (c >> x & 1) == y}}
	}.map{Integer.bitCount(_)}.max)
}