import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.PriorityQueue


object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val pq = new PriorityQueue[Int]
  val N, M = in.next().toInt

  val a = new Array[Int](M)
  val b = new Array[Int](M)
  for(i <- 0 until M) {
    val x, y = in.next().toInt
    a(i) = x
    b(i) = y
  }

  val _leftTo = new Array[(Int, Int)](M)
  for(i <- 0 until M) {
    _leftTo(i) = (a(i), b(i))
  }
  val leftTo = _leftTo.sorted

  var ans = 0
  for((a, b) <- leftTo) {
    if(pq.isEmpty)
      pq.enqueue(-b)
    else {
      val now = -pq.head
      if(now <= a){
        ans += 1
        pq.clear
        pq.enqueue(-b)
      }
      else {
        pq.enqueue(-b)
      }
    }
  }

  if(!pq.isEmpty) {
    ans += 1
  }
    

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
