#include <iostream>
#include <vector>
#include <map>

using namespace std;
map<int,vector<int>> mp;
bool dp[400010];
int main(){
    int i,n,m; cin >> n >> m;
    for(i=0;i<m;i++){
        int x,y; cin >> x >> y;
        mp[x].push_back(y);
    }
    for(i=0;i<=2*m;i++) dp[i] = false;
    dp[m] = true;
    map<int,bool> mp1;
    for(auto x:mp){
        vector<int> v = x.second;
        for(int y:v){
            if(y<n - m || y>n + m) continue;
            y -= n - m;
            //cout << x.first << " " << y << endl;
            if(y - 1>=0 && dp[y - 1]) mp1[y] = true;
            else if(y + 1<=2*m && dp[y + 1]) mp1[y] = true;
            else mp1[y] = false;
        }
        for(int y:v){
            if(y<n - m || y>n + m) continue;
            y -= n - m;
            //cout << x.first << " " << y << " " << mp1[y] << endl;
            if(mp1[y]) dp[y] = true;
            else dp[y] = false;
        }
        /*for(i=0;i<=2*m;i++) cout << dp[i];
        cout << endl;*/
    }
    int cnt = 0;
    /*for(i=0;i<=2*m;i++){
        cout << dp[i] << " ";
    }
    cout << endl;*/
    for(i=0;i<=2*m;i++) cnt += dp[i];
    cout << cnt << endl;
}
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

signed main(){
    int N,M;cin>>N>>M;

    map<int,vector<int>> v;
    rep(i,M){
        int h,w;cin>>h>>w;
        v[h].push_back(w);
    }

    set<int> st;
    st.insert(N);

    for(auto &p:v){
        vector<int> nxt,ers;
        for(auto &j:p.second){
            if(st.count(j)){
                if(!st.count(j-1) and !st.count(j+1)) ers.push_back(j);
            }else{
                if(st.count(j-1) or st.count(j+1)) nxt.push_back(j);
            }
        }
        for(auto &j:ers) st.erase(j);
        for(auto &j:nxt) st.insert(j);
    }
    cout<<st.size()<<endl;
    return 0;
}