object Main{
	def main(A:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n = s.nextInt
		val a = new Array[Int](s.nextInt)
		(1 to n).flatMap(_ => 1 to s.nextInt).foreach(_=>a(s.nextInt-1)+=1)
		println(a.count(i=>i==n))
	}
}