#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005];
vector<int> v[100005];
bool vis[100005];
int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i=1;i<=m;i++){
		scanf("%d%d", &a[i], &b[i]);
		v[a[i]].push_back(b[i]);
	}
	int ans = 0;
	int mn = 1e9;
	for(int i=1;i<=n;i++){
		if(mn == i){
			ans++;
			mn = 1e9;
		}

		for(int j=0;j<v[i].size();j++){
			mn = min(mn, v[i][j]);
		}
	}
	printf("%d\n", ans);
}