#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int n,m;
  cin >> n >> m;
  vector<P> v(m);
  rep(i,m)cin >> v[i].first >> v[i].second;
  sort(ALL(v));
  int pre = 0;
  int res = 0;
  rep(i,m){
    if(v[i].first <= pre)pre = min(pre,v[i].second);
    else{
      res++;
      pre = v[i].second;
    }
  }
  cout << n-res << "\n";
  

  return 0;
}