fun main(args: Array<String>) {
  val (N, M) = readInts()
  val AB = (1..M).map { readInts().let { it[0] to it[1] } }.sortedBy { it.second }
  var cnt = 0
  var r = 0
  for (i in 0 until M) {
    val ab = AB[i]
    val a = ab.first
    val b = ab.second
    if (r in (a + 1)..b) continue
    cnt++
    r = b
  }
  println(cnt)
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
