#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct node {
ll pos,type,id;
bool operator<(node b)const {
return id<b.id;
}
} nodes[2005];
ll cnter=0,vis[2005],qwq[2005];
int main() {
ll n,m;
cin >> n >> m;
for (ll i=1; i<=m; i++) {
ll f,t;
cin >> f >> t;
nodes[++cnter]= {f,1,i};
nodes[++cnter]= {t,0,i};
}
sort(nodes+1,nodes+cnter+1,[](node a,node b) {
if (a.type==0&&b.type==0)
return (a.pos==b.pos?a.id<b.id:a.pos<b.pos);
else
return (a.pos==b.pos?a.id>b.id:a.pos<b.pos);
});
priority_queue<node> pq;
for (ll i=1; i<=cnter; i++) {
if (nodes[i].type==1) {
pq.push(nodes[i]);
}
node tp= {0,0,0};
if (!pq.empty())
tp=pq.top();
while (!pq.empty()&&qwq[tp.id]) {
pq.pop();
tp=pq.top();
}
if (!qwq[tp.id]&&(abs(tp.pos-nodes[i].pos)>=1||tp.id==nodes[i].id))
vis[tp.id]=1;
if (nodes[i].type==0) {
qwq[nodes[i].id]=1;
}
}
ll cnt=0;
for (ll i=1; i<=m; i++)if (vis[i])cnt++;
cout << cnt;
return 0;
}