object Main extends App {
  val Array(n, m) = io.StdIn.readLine().split(' ').map(_.toInt)
  val against = (for(_ <- 0 until m toList) yield
    io.StdIn.readLine().split(' ').map(_.toInt) match {
      case Array(a, b) => (a-1, b-1)
    }).sortWith{case (x, y) => x._2 < y._2}

  @scala.annotation.tailrec
  def solver(against: List[(Int, Int)], end: Int = 0, count: Int = 0): Int = against match {
    case Nil => count
    case p :: rest if end <= p._1 => solver(rest, p._2, count+1)
    case _ :: rest => solver(rest, end, count)
  }

  println(solver(against))
}