//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,m;
vector<ii> v;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>m;
	
	int a,b;
	rep(x,0,m){
		cin>>a>>b;
		v.pub(ii(a,b));
	}
	
	sort(all(v),[](ii i,ii j){
		return i.fi>j.fi;
	});
	
	set<int> s={n};
	
	while (!v.empty()){
		set<int> remove;
		set<int> add;
		
		int curr=v.back().fi;
		while (!v.empty() && v.back().fi==curr){
			if (s.count(v.back().se-1) || s.count(v.back().se+1)) add.insert(v.back().se);
			else remove.insert(v.back().se);
			
			v.pob();
		}
		
		for (auto &it:remove) s.erase(it);
		for (auto &it:add) s.insert(it);
		
		//for (auto &it:s) cout<<it<<" "; cout<<endl;
	}
	
	cout<<sz(s)<<endl;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
#define vvl vector<vector<ll>>
#define vll vector<ll>
#define vpll vector<pll>
#define vvpll vector<vpll>
typedef pair<string, string> pss;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll inf = 1e18;
ll mod = 1e9 + 7;
ld eps = 1e-9;

ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);


}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("temp.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll  i, y, x, z, g, key,   h, a, b, c, j, q, n, d, k, l, r, m;
    ll t2, t3, t4, t1, t5, t6;
    string s, s2, s1;
    ll tc;
    //cin >> tc;
    tc = 1;
    while (tc--)
    {
        cin >> n >> m;
        pll arr[m];
        map<ll, set<ll>>ma;
        for (i = 0; i < m; i++)
        {
            cin >> arr[i].fi >> arr[i].se;
            ma[arr[i].fi].insert(arr[i].se);
        }
        ll cur = 0;
        set<ll>ans;
        ans.insert(n);

        for (auto u : ma)
        {
            auto st = u.se;
            set<ll>temp;
            for (auto v : st)
            {
                if (ans.find(v - 1) != ans.end())
                    temp.insert(v);
                if (ans.find(v + 1) != ans.end())
                    temp.insert(v);

            }
            for (auto v : st)
            {
                if (ans.find(v) != ans.end())
                {
                    ans.erase(v);
                }
            }
            for (auto v : temp)
                ans.insert(v);


        }
        t1 = ans.size();
        cout << t1;

    }




    return 0;
}