#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

signed main(){
    int N, M; cin>>N>>M;
    vec_int L(M), R(M);
    rep(i,M)cin>>L.at(i)>>R.at(i);
    vector<P> RL(M);
    rep(i,M)RL.at(i) = make_pair(R.at(i), L.at(i));
    sort(RL.begin(), RL.end());
    int zeros = 0;
    int right = 0;
    rep(i,M){
        if(RL.at(i).second>right){
            right = RL.at(i).first;
            zeros++;
        }
    }
    cout<<N-zeros<<endl;





    return 0;
}