#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e6+10,mod=998244353;
typedef long long LL;
struct Node{
	LL l,r;
	bool operator<(const Node &a)const{
		return r<a.r;
	}
}node[N];
int main(){
	LL n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++){
		cin>>node[i].l>>node[i].r;
	}
	sort(node+1,node+1+m);
	LL ed=-2e9-10,res=0;
    for(int i=1;i<=m;i++){
        if(node[i].l>ed){
            res++;
            ed=node[i].r;
        }
    }
	cout<<n-res;
	return 0;
}