#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  using P = pair<int,int>;
  vector<P> e(M);
  for(int i = 0,a,b; i < M; i++){cin >> a>>b,e[i]={b-1,a-1};}
  sort(e.begin(),e.end());
  int ans = 0;
  for(int i = 0,prev = -1; i < M; i++){
  	const int a = e[i].second,b=e[i].first;
    if(prev < a){ans++,prev=b-1;}
  }
  cout << ans << endl;
  
return 0;
}
