import java.util.Scanner

object Main{
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit ={

    val n = sc.nextInt
    val m = sc.nextInt


    val l = (1 to n).foldLeft(List.empty[List[Int]]) {(seq, i) =>
      val k = sc.nextInt
      seq :+ List.fill(k)(sc.nextInt)
    }

    val c = l.foldLeft((1 to m).toList)( _ intersect _)

    println(c.size)

  }

}