import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map {it.toInt()}
    val ps = ArrayList<Pair<Int, Int>>()

    for (i in 0 until M) {
        val (a, b) = readLine()!!.split(" ").map {it.toInt()}
        ps.add(Pair(a, b))
    }

    ps.sortWith(Comparator { a, b -> a.second - b.second })

    var res = 0
    var q = 0

    for (p in ps) {
        if (q <= p.first) {
            ++res
            q = p.second
        }
    }

    println(res)
}
