// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<int>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair
 
class SegmentTree{//RMQ 最小値を出すやつ
  public:
  SegmentTree(int n,V v);
  void updateVal(int pos,int val);
  int calcVal(int st,int en);//半開区間 3,6なら3,4,5の最小値
  V elements;
  int pnum;
};

SegmentTree::SegmentTree(int n,V v){
  pnum=1;while(pnum<n)pnum*=2;
  elements=V(pnum*2-1,MOD);
  
  REP(i,n)updateVal(i,v[i]);
}

void SegmentTree::updateVal(int pos,int val){
  function<void(int)> f = [&](int pos_l){
    elements[pos_l]=min(elements[pos_l*2+1],elements[pos_l*2+2]);
    if(pos_l)f((pos_l-1)/2);
  };
  int num = pos+pnum-1;
  elements[num]=val;
  if(num)f((num-1)/2);
}

int SegmentTree::calcVal(int st,int en){
  function<int(int,int,int,int,int)> f = [&](int st_l,int en_l,int node,int l,int r){
    if(r <= st_l || en_l <= l)return MOD;//交差しない
    if(st_l <= l && r <= en_l)return elements[node];
    int vl = f(st_l,en_l,node*2+1,l,(l+r)/2);
    int vr = f(st_l,en_l,node*2+2,(l+r)/2,r);
    return min(vl,vr);
  };
  return f(st,en,0,0,pnum);
}



int main(){
  CIN(n,m);
  VC2(m,a,b);
  V v(n,INF);
  REP(i,m)v[a[i]-1]=min(v[a[i]-1],b[i]-1);

  SegmentTree seg(n,v);
  int st = 0;
  int ans = 0;
  REP(i,n)
    if(seg.calcVal(st, i) == i){
      ++ans;
      st = i;
    }
  COUT(ans);

  return 0;
}


Measured memory_bytes: 2816