#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

const int MAXN = 1000;

int n;
int e[MAXN][2];

int d[MAXN];
int q[MAXN], qhead, qtail;

void solve() {
	REP(i, n) REP(j, 2) e[i][j] = (2 * i + j) % n;
	int cur = 0;
	REP(s, n) {
		REP(i, n) d[i] = INT_MAX;
		qhead = qtail = 0;
		d[s] = 0, q[qhead++] = s;
		while (qtail < qhead) {
			int at = q[qtail++];
			REP(j, 2) { int to = e[at][j]; if (d[to] == INT_MAX) d[to] = d[at] + 1, q[qhead++] = to; }
		}
		REP(i, n) cur = max(cur, d[i]);
	}
	assert(cur <= 10);
	//if (cur != INT_MAX) printf("%d\n", cur);
}

void run() {
	scanf("%d", &n);
	solve();
	REP(i, n) printf("%d %d\n", e[i][0] + 1, e[i][1] + 1);
}

void stress() {
	for (n = 1; n <= MAXN; ++n) { printf("solving %d\n", n); solve(); }
}

int main() {
	//stress();
	run();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) begin(v), end(v)
#define sz(v) v.size()
#define INF 1e18+9
#define EPSILON 1e-14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> pawn(M);
    rep(i, M){
        cin >> pawn.at(i).first >> pawn.at(i).second;
    }
    sort(all(pawn));
    set<ll> movable;
    movable.insert(N);
    ll row = 0;
    rep(i, M){
        set<ll> A, B;
        row = pawn.at(i).first;
        while(i < M && row == pawn.at(i).first){
            if(movable.count(pawn.at(i).second-1) || movable.count(pawn.at(i).second+1)){
                A.insert(pawn.at(i).second);
            }
            if(movable.count(pawn.at(i).second)){
                B.insert(pawn.at(i).second);
            }
            i++;
        }
        i--;
        for(ll x : B){
            movable.erase(x);
        }
        for(ll x : A){
            movable.insert(x);
        }
    }
    cout << sz(movable) << '\n';
}