import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, m) = readLine().split(' ').map(_.toInt)
  val favorites: List[Set[Int]] = (1 to n).map { i =>
    readLine().split(' ').map(_.toInt).toSeq.tail.toSet
  }.toList
  val result = favorites match {
    case (head: Set[Int]) :: tail =>
      tail.foldLeft(head) { case (product, set) =>
        product & set
      }
  }
  println(result.size)
}