
fun main(args:Array<String>):Unit {
    val m = readLine()!!.trim().split(' ').map(String::toInt)[1]
    val demands = Array(m){
        val (a, b) = readLine()!!.trim().split( ' ').map(String::toInt).sorted()
        Pair(a, b)
    }.sortedBy(Pair<Int, Int>::second)
    var count = 0
    var leftLand = 0
    demands.forEach {
        val (left, right) = it
        if (leftLand <= left){
            ++count
            leftLand = right
        }
    }
    println(count)
}