import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val req = Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .toArray
    .sortBy(e => e(1))

  def rec(cnt:Int, pos:Int, i:Int):Int = {
    if(i == m) cnt
    else if(pos < req(i)(0)) rec(cnt+1, req(i)(1)-1, i+1)
    else rec(cnt, pos, i+1)
  }

  val ans = rec(0,0,0)
  println(ans)
}