#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>

using namespace std;

int main(){
	int n, m; scanf("%d %d", &n, &m);
	vector<pair<int, int> > v(m);
	for(int i = 0; i < m; i++){
		int a, b; scanf("%d %d", &a, &b);
		v[i] = make_pair(b, a);
	}
	sort(v.begin(), v.end());
	int res = 0, p = 0;
	for(int i = 0; i < m; i++) if(v[i].second > p){
		res++;
		p = v[i].first - 1;
	}
	printf("%d\n", res);
	return 0;
}