import scala.io.StdIn._

object Main extends App {

  val Array(n,m) = readLine().split(" ").map(_.toInt)
  val A = Array.fill(n)(readLine().split(" ").map(_.toInt))
    .map(_.drop(1).map(_ -1))

  def solve() = {
    val ans = Array.fill(m)(0)
    A.foreach { list =>
      list.foreach { num =>
        ans(num) += 1
      }
    }
    ans.count(_ == n)
  }
  println(solve())

}

