object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, M = in.nextInt
  val Reqs = List.fill(M)((in.nextInt, in.nextInt)).sorted

  def next(reqs: List[(Int, Int)], min: Int, breaks: Int): Int = reqs match {
    case Nil => breaks + 1
    case (l, r) :: xs =>
      if (min <= l) next(xs, r, breaks + 1)
      else next(xs, math.min(min, r), breaks)
  }

  println(next(Reqs, Int.MaxValue, 0))
}