data class AB(val a: Int, val b: Int) {
    constructor(pc: List<Int>): this(pc[0], pc[1])
}
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val ab = Array(M) { AB(listOfInt(-1)) }.sortedBy { it.b }
    var now = ab[0].b
    var ans = 1
    for (m in 1 until M) {
        if (ab[m].a >= now || now > ab[m].b) {
            ans += 1
            now = ab[m].b
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }




