
fun main(args : Array<String>){
    val (n,m) = readLine()!!.split(' ').map{ it.toInt() }
    var hoge = Array(m,{Pair(0,0)})
    var nyan = Array(m,{Pair(0,0)})

    for(i in 0 until m){
        var (a,b) = readLine()!!.split(' ').map{ it.toInt() }
        hoge[i] = Pair(a,i)
        nyan[i] = Pair(b,i)
    }

    var ok = Array<Boolean>(m,{false})
    var now = 0
    var ans = 0
    hoge = hoge.sortedBy { it.first }.toTypedArray()
    nyan = nyan.sortedBy { it.first }.toTypedArray()

    for(i in 0 until m){
        if(ok[nyan[i].second])continue
        while(now < m && hoge[now].first < nyan[i].first){
            ok[hoge[now].second] = true
            now++
        }
        ans++
    }

    println(ans)

}
