#include<bits/stdc++.h>
using namespace std;
#define N 100010
int n,m,a,b,d[N];
vector<int> v[N];
int main(){
    scanf("%d%d",&n,&m);
    while(m--){
	scanf("%d%d",&a,&b);
	v[a].push_back(b);
    }
    for(int i=0;i<=n;i++)d[i]=0;
    for(int i=0;i<=n;i++){
	for(auto x:v[i])d[x]=max(d[x],d[i]+1);
	d[i+1]=max(d[i+1],d[i]);
    }
    printf("%d",d[n]);
    return 0;
}
