fun main(array: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var list = Array(m){0}.toMutableList()
        repeat(n) {
            val arr = readLine()!!.split(" ").map { it.toInt() }
            for(i in 1..m) {
                for(j in 1 until arr.size) {
                    if(i == arr[j]) {
                        list[i-1] += 1
                    }
                }
            }
        }

    var cnt = 0
    repeat(m) {
        if(list[it] == n) cnt++
    }
    print(cnt)
}