#include <bits/stdc++.h>
using namespace std;
int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0));
using Int = long long;
int main() {
    int N, M; cin >> N >> M;
    map<int, vector<int>> black;
    for (int i = 0; i < M; i++) {
        int x, y; cin >> x >> y;
        black[y].push_back(x);
    }
    for (auto &[y, xs] : black) {
        sort(begin(xs), end(xs));
    }
    set<pair<int, int>> visited;
    int ans = 0;
    stack<pair<int, int>> S;
    S.emplace(0, N);
    while (!S.empty()) {
        auto [x, y] = S.top();
        S.pop();
        if (visited.count(make_pair(x, y))) {
            continue;
        }
        visited.emplace(x, y);
        auto &C = black[y];
        auto itC = lower_bound(begin(C), end(C), x + 1);
        int xlim = -1;
        if (itC == end(C)) {
            ans++;
            xlim = 2 * N;
        } else {
            xlim = *itC;
        }
        auto &L = black[y - 1];
        auto itL = lower_bound(begin(L), end(L), x + 1);
        while (itL != end(L) && *itL <= xlim) {
            S.emplace(*itL, y - 1);
            ++itL;
        }
        auto &R = black[y + 1];
        auto itR = lower_bound(begin(R), end(R), x + 1);
        while (itR != end(R) && *itR <= xlim) {
            S.emplace(*itR, y + 1);
            ++itR;
        }
    }
    cout << ans << '\n';
    return 0;
}
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	map<int, vector<int>> pawns;
	rep(i, 0, M) {
		int X, Y; cin >> X >> Y;
		pawns[X].push_back(Y);
	}

	set<int> ans;
	ans.insert(N);

	fore(p, pawns) {
		set<int> ng;
		set<int> ok;
		fore(y, p.second) {
			if (ans.count(y - 1)) ok.insert(y);
			else if (ans.count(y + 1)) ok.insert(y);
			else ng.insert(y);
		}
		fore(i, ng) ans.erase(i);
		fore(i, ok) if (0 <= i && i <= 2 * N) ans.insert(i);
	}

	cout << ans.size() << endl;
}





