#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> ab(M, { 0,0 });
	for (int i = 0; i < M; i++) cin >> ab[i].second >> ab[i].first;
	sort(ab.begin(), ab.end());
	int ans = 0;
	int E = 0;
	for (int i = 0; i < M; i++) {
		if (ab[i].second >= E) {
			ans++;
			E = ab[i].first;
		}
	}
	cout << ans << endl;
}