object Main {
  def main(args:Array[String]) = {
    /* 文字列を読み込み、空白で分割して配列にし、Int型にする */
    val in1 = readLine.split(" ").map(_.toInt) 
    val N = in1(0)
    val M = in1(1)
    
    val pref = (0 until M).map(it => 0).toArray
    
    (0 until N).map{
    i =>
      val ai = readLine.split(" ").map(_.toInt) 
      val ki = ai(0)
      
      val prefi = (1 to ki).map(j => ai(j))
      
      prefi.foreach{
        i => 
        val prev = pref(i)
        pref.updated(i, prev + 1)
      }
    }
    
    val count = pref.filter(it => it == N).length
    println(count)
  }
}