import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()

    val likes = (0 until n).map {
        val length = sc.nextInt()
        parseList(sc, length)
    }
    val result = likes.flatten().groupBy { it }
    // 人数分好きと言われてるものに絞って数を数える
    val count = result.filter { it.value.size == n }.size
    println(count)
}

private fun parseList(scanner: Scanner, length: Int): List<Int> {
    return (0 until length).map {
        scanner.nextInt()
    }
}
