fun main(args : Array<String>) {
  val remove = mutableListOf<Int>()
  (1..readLine()!!.split(" ")[1].toInt())
    .map { readLine()!!.split(" ").map { it.toInt() } }
    .sortedBy { it[1] }
    .forEach { 
      if (remove.isEmpty()) remove.add(it[1] - 1)
      else if (it[0] > remove.last()) remove.add(it[1] - 1)
    }.run { print(remove.size) }
}