#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/
template<typename Monoid>
class SegmentTree {
public:
	using F = function<Monoid(Monoid, Monoid)>;

	ll size;
	vector< Monoid > seg;

	const F f;
	const Monoid M1;
 
	SegmentTree(ll n, const F f, const Monoid &M1) : f(f), M1(M1) {
		size = 1;
		while(size < n) size <<= 1;
		seg.assign(2 * size, M1);
	}
	
	void set(ll k, const Monoid &x) {
		seg[k + size] = x;
	}

	void build() {
		for(ll k = size - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}
	
	void update(ll k, const Monoid &x) {
		k += size;
		seg[k] = x;
		while(k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(ll a, ll b) {
		Monoid L = M1, R = M1;
		for(a += size, b += size; a < b; a >>= 1, b >>= 1) {
			if(a & 1) L = f(L, seg[a++]);
			if(b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid operator[](const ll &k) const {
		return seg[k + size];
	}
};



signed main() {
	vector<pair<ll,ll>> a;
	ll N,M;
	cin>>N>>M;
	a.assign(M,pair<ll,ll>());
	rep(i,M)cin>>a[i].first>>a[i].second;

	sort(a.begin(), a.end(), [](const pair<ll,ll> &x, const pair<ll,ll> &y) {
		return x.second < y.second;
	});

	//debug(a);

	ll bridgecount=0;
	SegmentTree<ll> st(N,[](ll a,ll b){return a+b;},0);

	rep(i,M){
		debug(a[i]);
		ll t=st.query(a[i].first,a[i].second+1);
		debug(t);
		if(t==0){
			bridgecount++;
			st.update(a[i].second-1,1);
			debug(bridgecount);
		}
	}


	p(bridgecount);
	return 0;
}


Measured memory_bytes: 3840