'use strict'

function main(s) {

  const spans = s.split('\n').slice(1, -1).map(l => l.split(' ').map(n => Number(n)));

  spans.sort((a, b) => a[1] - b[1]);

  let breaked = 0;
  let sum = 0;

  for (const span of spans) {
    const start = span[0];
    const end   = span[1];

    if (start >= breaked) {
      breaked = end;
      sum += 1;
    }
  }

  console.log(sum);
}

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