fun main(args: Array<String>) {
    abc118b()
}

fun abc118b() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val kaList = (1..n).map { readLine()!!.split(" ").map { it.toInt() }.drop(1) }

    var intersected = kaList[0].toSet()
    (1 until kaList.size).forEach { intersected = intersected.intersect(kaList[it]) }

    println(intersected.count())
}
