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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }

#define POS_MAX	((ll)2e5 + 5)
ll N, M;
VVL G(POS_MAX * 2);
VVL isUsed(POS_MAX * 2);

void dfs(ll x, ll y, ll cIdx)
{
	VL &posC = G[y];

	isUsed[y][cIdx] = true;

	ll xEnd;
	if (cIdx < posC.size() - 1) {
		xEnd = posC[cIdx + 1];
	} else {
		xEnd = N * 2 + 5;
	}

	auto execOne = [&](ll yNext) {
		VL &xNext = G[yNext];
		VL &isUsedOne = isUsed[yNext];
		ll i = upper_bound(ALL(xNext), x) - xNext.begin();
		for (; i < xNext.size(); i++) {
			if (!isUsedOne[i]) {
				if (x < xNext[i] && xNext[i] <= xEnd) {
					dfs(xNext[i], yNext, i);
				} else {
					break;
				}
			}
		}
	};

	execOne(y - 1);
	execOne(y + 1);
}

// 処理
void Solve()
{
	cin >> N >> M;
	REP(i, M) {
		ll x, y;
		cin >> x >> y;
		y -= N;
		if (-POS_MAX < y && y < POS_MAX) {
			y += POS_MAX;
			G[y].emplace_back(x);
			isUsed[y].emplace_back(false);
		}
	}

	isUsed[POS_MAX].emplace_back(false);
	G[POS_MAX].emplace_back(0);
	for (auto &g : G) {
		if (g.size()) {
			sort(ALL(g));
		}
	}

	dfs(0, POS_MAX, 0);

	ll ans = 0;
	for (auto u : isUsed) {
		if (u.size()) {
			if (u.back()) {
				ans++;
			}
		}
	}

	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}

#include<cstdio>
#include<functional>
#include<utility>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    pair<int, int> pawn[M];
    for (unsigned i = 0; i < M; i++) scanf("%d %d", &pawn[i].first, &pawn[i].second);
    set<int> valid_y;
    valid_y.insert(N);
    sort(pawn, pawn + M);
    bool pawn_exists_in_front = false, pawn_exists_in_left;
    for(unsigned i = 0;i < M;i++){
        pawn_exists_in_left = pawn_exists_in_front;
        pawn_exists_in_front = (valid_y.find(pawn[i].second) != valid_y.end()) && i < M-1 && pawn[i+1] == make_pair(pawn[i].first, pawn[i].second + 1);
        if(((i && pawn[i-1] == make_pair(pawn[i].first, pawn[i].second - 1)) ? pawn_exists_in_left : (valid_y.find(pawn[i].second - 1) != valid_y.end())) || (valid_y.find(pawn[i].second + 1) != valid_y.end())) valid_y.insert(pawn[i].second);
        else valid_y.erase(pawn[i].second);
    }
    printf("%u\n", valid_y.size());
	return 0;
}