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

#define int long long
#define mod 1000000007
#define pb push_back
#define ss second
#define ff first
#define all(v) v.begin(), v.end()
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)


int32_t main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n,k;
    cin >> n >> k;
    vector<pair<int,int>> v(k);

    for(int i = 0; i < k; ++i)
        cin >> v[i].ff >> v[i].ss;

    sort(all(v));

    set<int> can;
    can.insert(n);

    for(int i = 0; i < k;) {
        vector<int> rem,add;
        int temp = v[i].ff;

        while(i < k && v[i].ff == temp) {
            int l = can.count(v[i].ss - 1);
            int r = can.count(v[i].ss + 1);

            if(l + r == 0)
                rem.push_back(v[i].ss);
            else add.pb(v[i].ss);

            i++;
        }

        for(int j: rem)
            can.erase(j);

        for(int j: add)
            can.insert(j);
    }

    cout << can.size();
    
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }
    int x, y;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    int l = m + 1;

    vector<P> p;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        y += l - n;
        if (!(0 <= y && y <= l * 2)) continue;

        p.push_back({ x, y });
    }
    sort(p.begin(), p.end());

    vector<int> c(l * 2 + 1, 0);
    c[l] = 1;
    int x0 = -10, y0 = -10, c0 = -10;
    for (const auto &[x, y] : p) {
        int c1 = (x0 == x && y0 == y - 1) ? c0 : c[y - 1];
        x0 = x;
        y0 = y;
        c0 = c[y];
        c[y] = c1 | c[y + 1];
    }

    int r = 0;
    for (const auto &i : c) {
        r += i;
    }
    cout << r << endl;

    return 0;
}