import java.util.Scanner

object Main {
  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val N,M = sc.nextInt()
    val list = for (i <- 0.until(N)) yield {
      val K = sc.nextInt()
      List.fill(K)(sc.nextInt()).foldLeft(0)((pre, i) => pre | (1 << i))
    }
    val num = list.foldLeft(~0)((pre, i) => pre & i)
    println(Integer.bitCount(num))
  }
}
