#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
signed main(){
	int n,ans=0;
	cin>>n>>n;
	vector<P>v(n);
	r(i,n){
		int a,b;
		cin>>a>>b;
		v[i]=P(b,a);
	}
	sort(v.begin(),v.end());
	int now=-1;
	r(i,n){
		int en=v[i].first;
		int st=v[i].second;
		if(now<=st)now=en,ans++;
	}
	cout<<ans<<endl;
}