fun main(args: Array<String>) {
    fun read() = readLine()!!.split(" ").map(String::toInt)
    val (n, m) = read()
    var s = (1..m).map { it }.toSet()
    repeat(n) { s = s.intersect(read().drop(1)) }
    print(s.size)
}