#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map>
#include<stdio.h>
#include<queue>
#include<tuple>

#define ALL(a)  (a).begin(),(a).end()
const long long MOD = 1e9+7;

//いろんなstlの使い方　https://qiita.com/tukejonny/items/f4013547df761a0b3523
//http://y-mazun.hatenablog.com/entry/20111202/1322840281



using namespace std;


long long gcd(long long a, long long b) {
    if (a > b) {
        return gcd(b, a);
    }
    return a == 0 ? b : gcd(b % a, a);
}

int lcm(int m, int n) {
    // 引数に０がある場合は０を返す
    if ((0 == m) || (0 == n))
        return 0;

    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm


int moji(char in) {
    int ans = (int) in - (int) 'a';
    if ((ans < 0) || (ans > 25)) {
        ans = 26;
    }
    return ans;
}


int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int *) a - *(int *) b;
}



template<class T>
void chmin(T &a, T b) {
    if (a > b) {
        a = b;
    }
}

//formerは前方のindex(自分自身を含んで良い)
template<class T>
int former(const vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}

//latterは後方のindex(自分自身を含んで良い)
template<class T>
int latter(const vector<T> &v, T x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}



//indexを用いてvectorから要素削除
template<typename T>
void remove(std::vector<T> &vector, unsigned int index) {
    vector.erase(vector.begin() + index);
}

typedef long long ll;
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = max(node[i*2+1],node[i*2+2]);
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] = max(lazy[k],node[k]);
            if(r - l > 1) {
                lazy[2*k+1] = max(lazy[k],lazy[2*k+1]);
                lazy[2*k+2] = max(lazy[k],lazy[2*k+2]);
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = max(node[2*k+1],node[2*k+2]);
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
    ll getpoint(int a){
        return node[n-1+a];


    }
    void kaiji(){
        for(int i=0;i<node.size();i++){
            cout<<node[i]<<endl;
        }
    }


};

int main() {
    int N,M;
    cin>>N>>M;
    vector<pair<int,int>>x;
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        x.push_back((make_pair(b,a)));
    }
    sort(x.begin(),x.end());
    int sum=1;
    int now=x[0].first-1;
    for(int i=0;i<M;i++){
        if(x[i].second<=now){

        }else{
            sum++;
            now=x[i].first-1;
        }
    }
    cout<<sum<<endl;





    }
















Measured memory_bytes: 1400