import scala.io.{StdIn => in}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val table = Array.ofDim[Int](m+1)
  Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => {
      e.tail.foreach(table(_) += 1)
    })
  
  val ans = table.count(_ == n)
  out.println(ans)
  out.flush
}