fun main(args: Array<String>){
    val input: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    val n = input[0]
    val mList = Array(input[1], {i -> 0})
    var count = 0

    for(i in 0 until input[1]){
        mList[i] = 0
    }

    for(i in 0 until n){
        val nInput: List<Int> = readLine()!!.split(" ").map { it.toInt() }
        for(j in 1 until nInput[0]+1){
            mList[nInput[j]-1]++
        }
    }

    for(i in mList){
        if(i == n) count++
    }

    println(count)
}