// D - Islands War
#include <bits/stdc++.h>
using namespace std;

int in(){int x;scanf("%d",&x);return x;}

int main(){
	int N=in(), M=in();
	int V[100000]; for(int l=1; l<=N; ++l) V[l] = N+1;
	while(M--){
		int l=in(), r=in();
		V[l] = min(V[l], r);
	}
	int ans = 0, R = 0;
	for(int l=1; l<N; ++l){
		int r = V[l];
		if(r > N) continue;
		if(l >= R) R=r, ans++;
		R = min(R, r);
	}
	cout<< ans <<endl;
}