
object Q20200817 {
  case class Answer(
                     numberOfLikeFood: Int,
                     likeFoodIndexes: Seq[Int],
              )


  class AllHumanLikeKindFoodCount(val value: Int) extends AnyVal {
    override def toString: String = value.toString
  }

  object AllHumanLikeKindFoodCount {
    def apply(numberOfKindOfFood: Int, answers: Seq[Answer]): AllHumanLikeKindFoodCount = {
      new AllHumanLikeKindFoodCount((1 to numberOfKindOfFood)
        .count { foodIndex =>
          answers.forall(_.likeFoodIndexes.contains(foodIndex))
        })
    }
  }
}

object Main extends App {
  import Q20200817._

  import io.StdIn._
  val Array(numberOfHuman, numberOfKindOfFood) = readLine().split(' ').map(_.toInt)
  val stringToAnswer = (line: String) => {
    val numbers = line.split(' ')
    Answer(numbers.head.toInt, numbers.tail.map(_.toInt))
  }

  val inputs = (0 until numberOfHuman).map(_ => readLine()).map(stringToAnswer)
  println(AllHumanLikeKindFoodCount(numberOfKindOfFood, inputs))
}