#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 100005
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
#define memset1(v) memset(v,-1,sizeof(v))
#define memset0(v) memset(v,0,sizeof(v))
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	map<int,vector<int>>id;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		id[x].pb(y);
	}
	map<int,int>vis;
	vis[n]=1;
	for(auto p:id){
		int x=p.fi;
		map<int,int>vis1;
		for(int y:p.se){
			if(vis.find(y+1)!=vis.end())vis1[y]=1;
			if(vis.find(y-1)!=vis.end())vis1[y]=1;
		}
		for(int y:p.se)if(vis.find(y)!=vis.end())vis.erase(y);
		for(pii p1:vis1)vis[p1.fi]=1;
	}
	cout<<vis.size();
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}
#include <bits/stdc++.h>
#define INF LLONG_MAX/2
#define rep(i,n) for(int i = 0; i <(n) ; i++)
using namespace std;
typedef long long ll;
typedef  __int128_t LL; //入出力では使えないことに注意が必要. 計算過程で途中64bitを超える可能性があるときに使う
typedef pair<ll,ll> pll;
#define all(x) (x).begin(), (x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



// vector<vector<ll> > dp(N+1, vector<ll>(2, 0));
// vector<vector<vector<ll> > > dp(N, vector<vector<ll> >(M, vector<ll>(L, 0)));
int main(){
    ll N, M;
    cin >> N >> M;
    ll offset = 300010;
    vector<vector<bool> > dp(2, vector<bool>(600020, false));
    
    vector<pll> p;
    for(ll i=0; i<M; i++){
        ll x, y;
        cin >> x >> y;
        y-=N;
        if(y<-200010 || 200010<y){
            continue;
        }
        p.push_back(pll(x,y));
    }
    if(p.size()==0){
        cout << 1 << endl;
        return 0;
    }
    sort(all(p), greater<pll>());
    dp[0][0+offset] = true;
    dp[1][0+offset] = true;
    ll now_x= 0;
    while(p.size()>0) {
        pll point = p.back();
        p.pop_back();
        now_x = point.first;
        vector<ll> ys;
        ys.push_back(point.second);
        while(p.size()>0 && p.back().first==now_x){
            ys.push_back(p.back().second);
            p.pop_back();
        }
        for(ll pawn: ys){
            dp[1][pawn+offset] = dp[0][pawn-1+offset] || dp[0][pawn+1+offset];
        }

        dp[0] = dp[1];
    }
    ll ans = 0;
    for(ll i = 0; i<dp[0].size(); i++){
        ans += dp[0][i];
    }

    cout << ans << endl;
    return 0;
}