import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val M = sc.nextInt
    val A = Array.fill(N)(Array.fill(sc.nextInt)(sc.nextInt))

    val a = ArrayBuffer.fill(M)(0)
    A.foreach {
      _.foreach { i =>
        a(i - 1) = a(i - 1) + 1
      }
    }
    a.count(_ == N).toString
  }
}
