/*  Jai Shree Ram 🚩🚩🚩 */
#include "bits/stdc++.h"
#define ll long long int
#define oo 1000000000000000000
#define forr(i,n) for(int i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()
#define unique(v) sort(all(v)); v.resize(distance(v.begin(),unique(all(v))))
#define eb emplace_back
#define FF first
#define SS second
#define mem(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define popcount(x) __builtin_popcount(x)

using namespace std;

template<typename T>
ostream &operator<<(ostream &output,const vector<T> &v){ 
    if(v.empty()) return output;
    for(int i=0;i<v.size()-1;i++) output << v[i] <<" ";
    output << v.back();
    return output;
}
template<typename T>
istream &operator>>(istream &input,vector<T> &v){ 
    for(auto &i: v) cin >> i;
    return input;            
}


void __sol(){
    int n,M; cin >> n >> M;
    map<int,vector<int>> m;
    forr(i,M){
        int x,y; cin >> x >> y;
        m[x].eb(y);
    }
    set<int> s = {n};
    int last = 0;
    for(auto &g: m){
        vector<int> add , del;
        for(auto &i: g.SS){
            if(s.count(i-1)) add.eb(i);
            else if(s.count(i+1)) add.eb(i);
            else if(s.count(i)) del.eb(i);
        }
        for(auto &i: del) s.erase(i);
        for(auto &i: add) s.insert(i);
    }
    int ans = 0;
    cout << s.size();
    return;
}


int main(){ 
    fastio;
    int tc=1;  // cin >> tc;
    while(tc--) __sol();
    return 0;
}
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define vi vector<int>
#define pb push_back
using namespace std;
const int N=2e5+5;
ll dp[N*4][2];pii p[N];int n,useless;
map<int,int>m,M;int cnt;vi v[N*4];
int main()
{
	cin>>useless>>n;
	for(int i=0;i<n;i++)
	{
		cin>>p[i].F>>p[i].S;
		m[p[i].F]=1;
	}
	for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
		it->S=++cnt;
	for(int i=0;i<n;i++)p[i].F=m[p[i].F];
	m.clear();cnt=0;m[0]=m[2*useless]=m[useless]=1;
	for(int i=0;i<n;i++)m[p[i].S]=m[max(p[i].S-1,0)]=m[min(p[i].S+1,2*useless)]=1;
	for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
		it->S=++cnt;
	for(int i=0;i<n;i++)p[i].S=m[p[i].S];
	for(int i=0;i<n;i++)
		v[p[i].F].pb(p[i].S);
	dp[m[useless]][0]=dp[m[useless]][1]=1;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<v[i].size();j++)
			dp[v[i][j]][1]=min((v[i][j]!=1?dp[v[i][j]-1][0]:0)+(v[i][j]!=cnt?dp[v[i][j]+1][0]:0),1ll);
		for(int j=0;j<v[i].size();j++)
			dp[v[i][j]][0]=dp[v[i][j]][1];
	}
	int ans=0;
	for(int i=1;i<=m[2*useless];i++)ans+=min(dp[i][0],1ll);
	cout<<ans<<endl;
	return 0;
}