#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n,m,mn[N];
int main(){
	//freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i = 0;i < n;i++)mn[i] = 1e9;
	for(int i = 0,a,b;i < m;i++){
		scanf("%d%d",&a,&b);
		mn[a - 1] = min(mn[a - 1],b - 1);
	}
	int cur = 1e9,ans = 0;
	for(int i = 0;i < n;i++){
		if(cur == i){
			ans++;
			cur = 1e9;
		}
		cur = min(cur,mn[i]);
	}
	printf("%d\n",ans);
}  