#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef ENVIRONMENT_LINKED_BOOST
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#endif

using namespace std;
using uint  = unsigned int;
using ll    = long long;
using ull   = unsigned long long;
using lpair = std::pair<ll, ll>;
#define REP(i, a, b)    for (ll i = a; i < b; ++i)
#define REPREV(i, a, b) for (ll i = a; i > b; --i)

const int _ = []() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    return 0;
}();

template <typename value_t>
void resize(value_t& v, const value_t& val) { v = val; }
template <typename vec_t, typename value_t, typename... arg_t>
void resize(std::vector<vec_t>& v, const value_t& val, int size, arg_t... arg) {
    v.resize(size);
    for (auto& c : v) resize(c, val, arg...);
}
template <typename A, typename B>
void chmin(A& a, const B& b) { a = min(a, static_cast<A>(b)); };
template <typename A, typename B>
void chmax(A& a, const B& b) { a = max(a, static_cast<A>(b)); };

int main() {
    map<ll, vector<int>> mp;
    ll N, M;
    cin >> N >> M;
    REP(i, 0, M) {
        ll x, y;
        cin >> x >> y;
        mp[x].push_back(y);
    }
    set<ll> cur;
    cur.insert(N);
    for (auto& [x, v] : mp) {
        set<ll> tmp;
        for (ll y : v) {
            if (cur.count(y - 1) || cur.count(y + 1)) tmp.insert(y);
        }
        for (ll y : v) cur.erase(y);
        cur.insert(tmp.begin(), tmp.end());
    }
    cout << cur.size() << endl;
    return 0;
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, int>;

ll n, m;
int MAX = 400010;
vector<ll> dp(MAX * 2, 0);
vector<vector<int>> G(MAX);
vector<int> seen(MAX, false);

void dfs(int v) {
    seen[v] = true;

    for (auto &nv : G[v]) {
        dp[nv] += dp[v];
        if (nv >= MAX || seen[nv]) continue;

        dfs(nv);
    }
}

int main() {
    cin >> n >> m;
    vector<set<P>> v(2 * m + 2);

    vector<ll> x(m), y(m);

    v[m + 1].insert({0, 0});
    rep(i, m) {
        cin >> x[i] >> y[i];
        if (y[i] - n + m + 1 >= 0 && y[i] - n + m + 1 < 2 * m + 2)
            v[y[i] - n + m + 1].insert({x[i], i + 1});
    }

    rep(i, 2 * m + 2) {
        if (!v[i].empty()) {
            G[(*v[i].rbegin()).second].push_back(MAX + i);
        }
    }
    rep(i, 2 * m + 2) {
        if (v[i].empty()) continue;
        if (i - 1 >= 0 && v[i - 1].size()) {
            auto it1 = v[i - 1].begin();
            ll next = 2 * n;
            auto it2 = v[i].begin();
            while (it2 != v[i].end()) {
                it2++;
                if (it2 != v[i].end())
                    next = (*it2).first;
                else
                    next = 2 * n;
                it2--;
                while (it1 != v[i - 1].end() && (*it1).first <= (*it2).first)
                    it1++;
                while (it1 != v[i - 1].end() && (*it1).first <= next) {
                    G[(*it2).second].push_back((*it1).second);
                    it1++;
                }
                it2++;
            }
        }
        if (i + 1 < 2 * m + 2 && v[i + 1].size()) {
            auto it1 = v[i + 1].begin();
            ll next = 2 * n;
            auto it2 = v[i].begin();
            while (it2 != v[i].end()) {
                it2++;
                if (it2 != v[i].end())
                    next = (*it2).first;
                else
                    next = 2 * n;
                it2--;
                while (it1 != v[i + 1].end() && (*it1).first <= (*it2).first)
                    it1++;
                while (it1 != v[i + 1].end() && (*it1).first <= next) {
                    G[(*it2).second].push_back((*it1).second);
                    it1++;
                }
                it2++;
            }
        }
    }
    dp[0] = 1;
    dfs(0);

    ll ans = 0;
    for (int i = MAX; i < MAX + 2 * m + 2; i++) ans += dp[i];
    cout << ans << endl;
}