object Main extends App {
  val in = io.StdIn.readLine.split(' ').map(_.toInt)

  val N = in.head
  val M = in.last

  val Ks = for (i <- 1 to N) yield io.StdIn.readLine.split(' ').map(_.toInt)

  val out = Ks.foldLeft(Ks(0).toSet)((accum, as) => as.tail.toSet.intersect(accum)).size

  println(out)
}
