object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val List(n, m) = sc.nextLine.split(" ").map(_.toInt).toList
  val a = List.fill(n){
    sc.nextLine.split(" ").tail.map(_.toInt)
  }

  val ans = a.flatten.groupBy(identity).mapValues(_.size).toList.filter(_._2 == n).size

  println(ans)
}
