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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < int(NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)

const ld pi = acosl(-1.0);

template <typename T>
void chmin(T& a, T b){ if(a > b) a = b; }
template <typename T>
void chmax(T& a, T b){ if(a < b) a = b; }

ll n,m;

ll in(ll y)
{
    return -m-2 <= y-n && y-n <= m+2;
}

ll c(ll y)
{
    return y - n + m+2;
}

int main()
{
	cin.tie( 0 ); ios::sync_with_stdio( false );
	// ----------------------------------------------------------------
	
	cin>>n>>m;
	vector<pair<ll,ll>> p( m );
    REP(i,m) cin>>p[i].first>>p[i].second;
    sort(ALL(p));
    map<ll, vector<ll>> xy;

    REP(i,m)
    {
        if(xy.count(p[i].first)<=0) xy[p[i].first] = vector<ll>(0);
        xy[p[i].first].emplace_back(p[i].second);
    }
    
    vector<bool> dp(2*m+5,false);
    map<ll, bool> update;
    dp[c(n)] = true;
    for( auto i = xy.begin(); i != xy.end() ; ++i )
    {
        //cout << i->first << ": "; REP( i, dp.size() ) cout << dp[i] << " "; cout << endl;
        //ll x = i->first;
        vector<ll>& ylist = i->second;

        update.clear();
        REP(j,ylist.size())
        {
            ll y = ylist[j];
            for(ll d=0;d<=1;d=((d==0)?-1:d+2))
            {
                if(!(in(y)&&in(y+d))) continue;
                if(d==0)
                    update[y] = false;
                else if(dp[c(y+d)])
                    update[y] = true;
            }
        }

        for( auto j = update.begin(); j != update.end() ; ++j )
        {
            //cout << i->first << ": " << j->first << " " << j->second << endl;
            dp[c(j->first)] = j->second;
        }
    }

    ll ans = 0;
    REP(i,dp.size())
        if(dp[i] == true) ++ans;
    cout << ans << endl;
	
	// ----------------------------------------------------------------
	return 0;
}
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0), cin.tie(nullptr)
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define fi first
#define se second
#define cat(a, b) a##b

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll S = 200000 + 10, MOD = (ll)1e9 + 7;
pii arr[S];
bool chk[S * 2];
int main() {
	fast;
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> arr[i].fi >> arr[i].se;
	sort(arr, arr + m);
	chk[m + 1] = 1;
	vector<vector<pii>> v{ {arr[0]} };
	for (int i = 1; i < m; i++) {
		if (arr[i - 1].fi != arr[i].fi)
			v.push_back({});
		v.back().push_back(arr[i]);
	}
	queue<int> pos, impos;
	for (auto i : v) {
		for (pii j : i) {
			if (abs(j.se - n) > m or j.fi == 0)
				continue;
			int idx = j.se - n + m + 1;
			if (chk[idx - 1] or chk[idx + 1]) {
				if (!chk[idx])
					pos.push(idx);
			}
			else {
				if (chk[idx])
					impos.push(idx);
			}
		}
		while (!pos.empty()) {
			chk[pos.front()] = true;
			pos.pop();
		}
		while (!impos.empty()) {
			chk[impos.front()] = false;
			impos.pop();
		}

	}
	int ans = 0;
	for (int i = 1; i <= 2 * m + 1; i++)
		ans += chk[i];
	cout << ans;
	return 0;
}