#include<bits/stdc++.h>
using namespace std;
#define mx 100005
#define P pair<int, int>

int n, m, a, b, ans, pos;
P brd[mx];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++){
		scanf("%d%d", &a, &b);
		brd[i] = P(b, a);
	}
	sort(brd, brd+m);
	for(int i = 0; i < m; i++){
		if(brd[i].second >= pos){
			ans++;
			pos = brd[i].first;
		}
	}
	printf("%d\n", ans);
}