object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M = sc.nextInt()
  val As = List.fill(N)(List.fill(sc.nextInt())(sc.nextInt()))
  println(As.flatten.groupBy(identity).count(_._2.length == N))
}
