import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt

    val evs =
      (0 until n).map { _ =>
        val a = in.readLine().toInt
        (0 until a).map { _ =>
          in.readLine().split("\\s+").map(_.toInt) match {
            case Array(x, y) => Array(x - 1, y)
          }
        }
      }

    System.out.println(
      (0 until (1 << n)).map { i =>
        if (evs.zipWithIndex.filter {
          case (ev, evIndex) => ((i >> evIndex) & 1) == 1
        }.forall {
          case (ev, evIndex) =>
            ev.forall { e =>
              ((i >> e(0)) & 1) == e(1)
            }
        }) {
          countBit(i)
        } else {
          0
        }
      }.max
    )
  }

  def countBit(n: Int): Int = {
    if (n == 0) {
      0
    } else {
      countBit(n / 2) + n % 2
    }
  }
}
