fun main (args : Array<String>) {
	val (n, m) = readLine()!!.split(" ")
	val N : Int = n.toInt()
	val M : Int = m.toInt()
	var cList : MutableList<Int> = mutableListOf()
	var count : Int = 0
	var result : Int = 0
	for (i in 0..N - 1) {
		var like = readLine()!!.split(" ").toMutableList()
		like.removeAt(0)
		for (j in like) {
			cList.add(j.toInt())
		}
	}
	for (i in 0..M) {
		for (j in 0..cList.size - 1) {
			if (cList[j] == i) {
				count++
			}	
		}
		if (count == N) {
			result++
			count = 0
		} else {
			count = 0
		}
	}
	println("${result}")
}