#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
#define forr(i,x,n) for(int i = n;i >= x;--i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)

const int N = 2e5+7;
int x[N],y[N];
map<int,vector<int>> E;

int main()
{
    int n,m;scanf("%d%d",&n,&m);
    forn(i,1,m)
    {
        int x,y;scanf("%d%d",&x,&y);
        E[x].push_back(y);
    }
    set<int> st;
    st.insert(n);

    for(auto& _ : E)
    {
        vector<int> nxt;
        for(auto& v : _.second) if(st.count(v - 1) || st.count(v + 1))    nxt.push_back(v);
        for(auto& v : _.second) st.erase(v);
        for(auto& v : nxt)  st.insert(v);
    }
    printf("%d\n",(int)st.size());
 
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

map<lli,vector<lli>> G;

void func(long long N, long long M, std::vector<long long> X, std::vector<long long> Y){
    REP(i,0,M){
        G[X[i]].push_back(Y[i]);
    }

    set<lli> nowS;
    nowS.insert(N);

    for(auto &e:G){
        set<lli> eraseS;
        set<lli> nextPushS;
        vector<lli> &nowV = e.second;
        for(auto now:nowV){
            if(nowS.find(now-1) != nowS.end()){
                nextPushS.insert(now);
            }
            if(nowS.find(now+1) != nowS.end()){
                nextPushS.insert(now);
            }
            if(nowS.find(now) != nowS.end()){
                eraseS.insert(now);
            }
        }
        for(auto e:eraseS){
            nowS.erase(e);
        }
        for(auto e:nextPushS){
            nowS.insert(e);
        }
    }
    cout<<nowS.size()<<endl;

    



}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> X(M);
    std::vector<long long> Y(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
    }
    func(N, M, std::move(X), std::move(Y));
    return 0;
}
