console.log((args=>{
  const [[N,M],...req] = args.trim().split('\n').map( r=>r.split(' ').map(v=>v|0));
  req.sort((a,b)=>a[1]-b[1]);
  const mfl = [req[0][1]-1];
  for ( let i = 1; i < M; i++ ) {
    if ( mfl[mfl.length-1] < req[i][0] ) mfl.push( req[i][1]-1 );
  }
  return `${mfl.length}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
