//include
//-------------------------
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<ctime>

using namespace std;

//conversion
//-----------------------
inline int toInt(string s) { int v;istringstream sin(s);sin >> v;return v; }
template<class T>inline string toString(T x) { ostringstream sout;sout << x;return sout.str(); }

//math
//-----------------------
template<class T>inline T sqr(T x) { return x * x; }

//using
//-----------------------
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using TIII = tuple<int, int, int>;
using VTIII = vector<TIII>;
using LL = long long;

//function
enum priority_code {
	fs,
	sf,
};
template<class T = void, priority_code t = fs>
struct greater_pair {
	constexpr bool operator()(const T& _Left, const T& _Right)const {
		if (t == sf)
			return (_Left.second > _Right.second ||
			(!(_Right.second > _Left.second) && _Left.first > _Right.first));
		else
			return (_Left.first > _Right.first ||
			(!(_Right.first > _Left.first) && _Left.second > _Right.second));
	}
};
template<class T = void, priority_code t = fs>
struct less_pair {
	constexpr bool operator()(const T& _Left, const T& _Right)const {
		if (t == sf)
			return (_Left.second < _Right.second ||
			(!(_Right.second < _Left.second) && _Left.first < _Right.first));
		else
			return (_Left.first < _Right.first ||
			(!(_Right.first < _Left.first) && _Left.second < _Right.second));
	}
};


//container util
//-----------------------
#define WHOLE(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define RWHOLE(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); })(x)
#define CWHOLE(f,x,...) ([&](decltype((x)) whole) { return (f)(cbegin(whole), cend(whole), ##__VA_ARGS__); })(x)
#define CRWHOLE(f,x,...) ([&](decltype((x)) whole) { return (f)(crbegin(whole, crend(whole), ##__VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto&& i :c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define sort(c) sort((c).begin(),(c).end())
#define RESET(c) int _c=(c).size();(c).clear();(c).resize(_c);
#define EACH_INPUT(x) EACH(itr,x)cin>>*itr;
#define EACH_OUTPUT(x) EACH(itr,x)cout<<*itr<<endl;

// repetition
//----------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define repeat(i,n) FOR(i,0,n)

//constant
//----------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a).0,sizeof(a))

//debug
//#define DEBUG
#ifdef DEBUG
#define dump(x) cerr<<#x<<"="<<(x)<<endl;
#define dump_pair(x) cerr<<#x<<"=["<<(x).first<<", "<<(x).second<<" ]"<<endl;
#define dump_tuple3(x) cerr<<#x<<"=["<<get<0>((x))<<", "<<get<1>((x))<<", "<<get<2>((x))<<" ]"<<endl;
#define debug(x) cerr<<#x<<"="<<(x)<<"(L"<<__LINE__<<")"<<""<<__FILE__<<endl;
#else
#define dump(x)
#define dump_pair(x)
#define dump_tuple(x)
#define debug(x)
#endif
//#define STAY
#ifdef STAY
#define stay cout<<"Push any key and Enter..."; scanf_s("%*s");
#else
#define stay
#endif

int main() {

	int n, m;cin >> n >> m;
	vector<tuple<int, int, int>> border;//position, is begin, id
	repeat(i, m) {
		int f, l;cin >> f >> l;
		border.PB(make_tuple(f, 1, i));
		border.PB(make_tuple(l, 0, i));
	}
	sort(border);

	queue<int> idque;
	bool id[200000] = {};
	int res = 0;
	repeat(i, (border.size())) {
		if (get<1>(border[i])) {
			id[get<2>(border[i])] = true;
			idque.push(get<2>(border[i]));
		}
		else if(id[get<2>(border[i])]){
			while (!idque.empty()) {id[idque.front()] = false;	idque.pop();}
			++res;
		}

	}
	cout << res << endl;

	stay;
	return 0;
}

Measured memory_bytes: 4852