
fun main(args: Array<String>){
    val inputList = readLine()!!.split(" ").map{ it.toInt() }
    val n = inputList[0]
    val m = inputList[1]
    var isFirst = true
    val answerList: MutableList<Int> = mutableListOf<Int>()

    for (i in 0 until n) {
        val aList = readLine()!!.split(" ").map{ it.toInt() }.drop(1)
        if (isFirst) {
            answerList.addAll(aList)
            isFirst = false
            continue
        }
        answerList.retainAll { aList.contains(it) }
    }

    println(answerList.size)
}
