#include <bits/stdc++.h>
using namespace std;

int main(){
	int N, M; cin >> N >> M;
	vector<int> ab(N+1, (int)1e8);
	for(int i=0; i<M; ++i){
		int l, r; cin >> l >> r;
		ab[l] = min(ab[l], r);
	}

	int ans = 0, r=1e8;
	for(int l=1; l<=N; ++l){
		if(l == r){
			++ans;
			r = 1e8;
		}
		r = min(r, ab[l]);
	}

	cout << ans << endl;
}
