import * as fs from "fs" const main = (args: string[]): void => { const [N, M] = args[0].split(" ").map(x => Number(x)) const LR = args.slice(1, -1).map(x => x.split(" ").map(v => Number(v))) LR.sort((x, y) => x[1] > y[1] ? 1 : -1) let ans = N let lst = -1 for (let i = 0; i < M; i++) { let [l, r] = LR[i] if (l <= lst && lst <= r) continue ans-- lst = r } console.log(ans) } main(fs.readFileSync('/dev/stdin', 'utf8').split("\n"));