#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<ll,ll>
#define il inline
#define LEFT POS*2
#define RIGHT POS*2+1
#define fastio ios::sync_with_stdio(false), cin.tie(0)
const int N = 1e4+5;
ll n,m,A[N],B[N],lsh[N],tlt;
unordered_map<ll,ll> cvt;
bool vis[5*N];
struct Node{
ll sum,l,r,lazy=0;
};
struct SGT{
Node tr[4*N];
ll base[N];
il void _pushup(ll POS){
tr[POS].sum = tr[LEFT].sum + tr[RIGHT].sum;
return ;
}
il void _pushdown(ll POS){
if(!tr[POS].lazy) return ;
tr[LEFT].sum = (tr[LEFT].r-tr[LEFT].l+1) * tr[POS].lazy;
tr[RIGHT].sum = (tr[RIGHT].r-tr[RIGHT].l+1) * tr[POS].lazy;
tr[LEFT].lazy = tr[POS].lazy;
tr[RIGHT].lazy = tr[POS].lazy;
tr[POS].lazy = 0;
return ;
}
il void build(ll POS,ll l,ll r){
tr[POS].l=l,tr[POS].r=r, tr[POS].sum=tr[POS].lazy=0;
if(l==r) return ;
ll mid = l+r>>1;
build(LEFT,l,mid),build(RIGHT,mid+1,r);
return ;
}
il void modify(ll POS,ll cl,ll cr,ll v){
ll l=tr[POS].l,r=tr[POS].r;
if(cl>r || cr<l) return ;
if(l>=cl && r<=cr){
tr[POS].sum = (r-l+1) * v;
tr[POS].lazy = v;
return ;
}
_pushdown(POS);
modify(LEFT,cl,cr,v),modify(RIGHT,cl,cr,v);
_pushup(POS);
return ;
}
il ll query(ll POS,ll cl,ll cr){
ll l=tr[POS].l,r=tr[POS].r;
if(cl>r || cr<l) { return 0; }
if(l>=cl && r<=cr) { return tr[POS].sum; }
_pushdown(POS);
return query(LEFT,cl,cr) + query(RIGHT,cl,cr);
}
} sgt;
signed main(){
fastio;
cin >> n >> m;
lsh[++tlt] = n;
for(int i=1; i<=m; i++){
cin >> A[i] >> B[i];
lsh[++tlt] = A[i], lsh[++tlt] = B[i], lsh[++tlt] = B[i]+1;
}
sort(lsh+1,lsh+tlt+1);
tlt = unique(lsh+1,lsh+tlt+1) - lsh - 1;
for(int i=1; i<=tlt; i++) cvt[lsh[i]] = i;
sgt.build(1,1,tlt);
for(int i=1; i<=m; i++) sgt.modify(1,cvt[A[i]],cvt[B[i]],i);
for(int i=1; i<=tlt; i++) vis[sgt.query(1,i,i)] = 1;
ll ans = 0;
for(int i=1; i<=tlt; i++) if(vis[i]) ans++;
printf("%lld\n", ans);
return 0;
}