#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define FOR(a,b,c) for(ll (a)= (b);(a)<(c);++(a))
#define REP(a,b) FOR(a,0,b)
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define f first
#define s second
ll ttt = 1, n;

template <class myType>
void print_arr(myType &arr, ll L, string sep){
    REP(i,L){
        cout << arr[i];
        if (i < L-1){
            cout << sep;
        }
    }
    cout << endl;
    return;
}

/*

*/

void solve(){
    ll m;
    cin >> n >> m;
    ll x, y;
    set<ll> pos;
    map<ll,set<ll>> G;
    set<ll> rows;
    REP(i,m) {
        cin >> x >> y;
        G[x].insert(y);
        rows.insert(x);
    }
    pos.insert(n);
    for (ll x: rows) {
        vector<ll> to_add, to_remove;
        for (ll y: G[x]) {
            //cout << "Y:" << y << endl;
            if (y > 0 && pos.find(y-1) != pos.end()) to_add.pb(y);
            if (y < 2*n-1 && pos.find(y+1) != pos.end()) to_add.pb(y);
            to_remove.pb(y);
        }
        //print_arr(to_add,to_add.size()," ");
        //print_arr(to_remove,to_remove.size()," ");
        for (ll y: to_remove) {
            pos.erase(y);
        }
        for (ll y: to_add) {
            pos.insert(y);
        }
        /*cout << "ROW " << x << endl;
        for (ll y: pos) {
            cout << y << endl;
        }*/
    }
    cout << pos.size() << endl;
    return;
}


int main(){  
    quick;
    //cin >> ttt;
    while (ttt--) solve();
    return 0;
}

/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - White Pawn
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 200000;

/* typedef */

typedef pair<int,int> pii;
typedef pair<int,bool> pib;
typedef queue<pib> qpib;

/* global variables */

pii xys[MAX_M];
bool cs[MAX_M * 2 + 1];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int m2 = m * 2;

  for (int i = 0; i < m; i++) scanf("%d%d", &xys[i].first, &xys[i].second);
  sort(xys, xys + m);

  cs[m] = true;
  for (int i = 0; i < m;) {
    int xi = xys[i].first;
    qpib q;
    while (i < m && xys[i].first == xi) {
      int yi = xys[i].second - n + m;
      if (yi >= 0 && yi <= m2) {
	if ((yi > 0 && cs[yi - 1]) || (yi < m2 && cs[yi + 1]))
	  q.push(pib(yi, true));
	else if (cs[yi])
	  q.push(pib(yi, false));
      }
      i++;
    }

    while (! q.empty()) {
      pib yb = q.front(); q.pop();
      cs[yb.first] = yb.second;
    }
  }

  int cnt = 0;
  for (int i = 0; i <= m2; i++)
    if (cs[i]) cnt++;

  printf("%d\n", cnt);
  return 0;
}
