fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    var list: MutableList<Pair<Int, Int>> = mutableListOf()
    for (i in 1..m) {
        val (a, b) = readLine()!!.split(" ").map(String::toInt)
        val pair = if (a < b) Pair(a, b) else Pair(b, a)
        list.add(pair)
    }

    list.sortBy { p -> p.first }

    var res = 0
    var first = 0
    var prevSecond = 0
    for (p in list) {
        if (first < p.first && prevSecond <= p.first) {
            first = p.first
            prevSecond = p.second
            res++
        } else {
            if (prevSecond > p.second) {
                prevSecond = p.second
            }
        }

    }

    println(res)
}