object Main extends App {
  val Array(n, m) = io.StdIn.readLine.split(" ").map(_.toInt)
  val kas = for (_ <- 1 to n) yield io.StdIn.readLine.split(" ").map(_.toInt)

  val as = kas.map(_.tail)
  val a_series = as.reduce(_ intersect _)
  println(a_series.length)
}