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

  var end = 0
  var count = 0
  for ((a,b) <- against) {
    if (end <= a) {
      end = b
      count += 1
    }
  }

  println(count)
}