import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val t = (1..n).map {
        val k = sc.nextInt()
        (1..k).map { sc.nextInt() - 1 }.fold(0, {acc, x -> acc or (1 shl x)})
    }.fold((1 shl m) - 1, {acc, x -> acc and x})
    println(Integer.bitCount(t))
}