fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val favorite_list:MutableList<Int> = mutableListOf()
    favorite_list.addAll((1..M).map{ 0 })

    (1..N).forEach { i ->
        val kan = readLine()!!.split(" ").map(String::toInt)
        val K = kan[0]
        0.until(K).forEach { k ->
            favorite_list[kan[k + 1] - 1] += 1
        }
    }

    favorite_list.filter { it == N }.size.run(::println)
}