function main(s){
  s = s.split("\n");
  var n = s[0].split(" ").map((a) =>{
    +a
  });
  var m = n[1]
  n = n[0]
  
  var a = [];
  for(var i = 0; i < m; i++){
    a[i] = s[i+1].split(" ").map(a=>+a)
  }
  
  a.sort((a,b) => {
    a[1]-b[1]
  })
  
  var ans = 0;
  var l = 0, r = 0;
  for(i = 0; i < m; i++){
    if(r <= a[i][0]){
      ans++ 
      r = a[i][1]
    }
  }
  console.log(ans);
}
main(require("fs").readFileSync("/dev/stdin","utf8"));