import java.util.Scanner

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val n = sc.nextInt()
    val testimony = Vector.fill(n) {
      val m = sc.nextInt()
      Vector.fill(m) {
        val a, b = sc.nextInt()
        (a, if (b == 1) true else false)
      }
    }

    val bits = bitSearch(n, Vector(true, false))

    val ans =
      bits
        .filter { bit =>
          bit.zipWithIndex.forall {
            case (b, i) =>
              if (!b) true
              else {
                testimony(i).forall {
                  case (x, y) => bit(x - 1) == y
                }
              }
          }
        }
        .map(_.count(_ == true))
        .max

    println(ans)
  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }

  def printExecTime(process: => Unit): Unit = {
    val start = System.currentTimeMillis
    process
    debug("処理時間： " + (System.currentTimeMillis - start) + " ミリ秒")
  }

  def bitSearch[T](n: Int, choice: Vector[T]): Vector[Vector[T]] = {
    @tailrec
    def bitSearchLogic(n: Int,
                       choice: Vector[T],
                       acc: Vector[Vector[T]]): Vector[Vector[T]] = {
      if (n == 0) acc
      else {
        val newAcc =
          acc.flatMap(vec => {
            choice.map(c => vec :+ c)
          })
        bitSearchLogic(n - 1, choice, newAcc)
      }
    }

    val firstAcc = choice.map(i => Vector(i))
    bitSearchLogic(n - 1, choice, firstAcc)
  }
}
