object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val a = List.fill(n)(List.fill(sc.nextInt())(sc.nextInt()))
  val merged = a.foldLeft(Nil: List[Int])(_ ++ _)
  val kv = merged.groupMapReduce(identity)(_ => 1)(_ + _)
  val ans = kv.filter{ case (k, v) => v == n}.size
  println(ans)
}