object Main extends App {
  val n = io.StdIn.readLine().toInt
  
  def readData(i: Int, acc: Map[Int, Set[(Int, Int)]]): Map[Int, Set[(Int, Int)]] = if (i > n)
  	acc
  else {
    val a = io.StdIn.readLine().toInt
    val testimony = Iterator.continually(io.StdIn.readLine()).take(a).map(_.split(' ').map(_.toInt)).map {
      case Array(x, y) => (x, y)
    }.toSet
    readData(i + 1, acc + (i -> testimony))
  }
  
  val testimonies = readData(1, Map.empty)
  
  val all = 1 to n
  
  def checkConsistent(unkinds: Set[Int]): Boolean = {
    val honests = all.toSet -- unkinds
    honests.forall { i =>
      	testimonies.getOrElse(i, Set.empty).forall {
          case (x, 0) => unkinds.contains(x)
          case (x, 1) => honests.contains(x)
          case z => throw new Exception(s"予想しない値です: ${z}")
        }
    }
  }
  
  def findUnkinds(unkinds: Int): Int = if (unkinds == n)
  	n
  else {
  	val consistent = all.combinations(unkinds).exists { candidates =>
      checkConsistent(candidates.toSet)
    }
    if (consistent)
    	unkinds
    else
    	findUnkinds(unkinds + 1)
  }
  
  val answer = findUnkinds(0)
  
  println(n - answer)
}