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

    val a = IntArray(n*m) { 0 }

    var c = 0
    for (i in 1..n) {
        val k = scn.nextInt()
        for (j in 0..k-1) {
            a[c++] = scn.nextInt()
        }
    }

    c = 0
    for (j in 1..m) {
        var count = 0
        for (i in 0..m*n-1) {
            if (a[i] == j) count++
        }
        if (count == n) c++
    }
    println(c)
}