"use strict"

function main(input) {
    let elims = []
    let lastelim = 0
    let arry = input.split('\n').map(x => x.split(' ').map(Number))
    let meta = arry.shift()
    //sort asc by b
    arry = arry.sort((x, y) => x[1] - y[1]) // 昇順にアソート
    let o
    for (let i in arry) {
        o = arry[i]
        if (lastelim < o[0]) {
            lastelim = o[1] - 1
            elims.push(lastelim)
        }
    }

    console.log(elims.length);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
