import scala.io.StdIn._

object Main extends App {
  val Seq(n, m) = readLine().split(" ").map(_.toInt).toSeq

  require(1 <= n && n <= 30)
  require(1 <= m && m <= 30)

  var i = 0
  var f = readLine().split(" ").map(_.toInt).toSeq.tail
  while (i < n - 1) {
    val arr = readLine().split(" ").map(_.toInt).toSeq
    f = f.intersect(arr.tail)
    i = i + 1
  }
  println(f.length)
}
