#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

const int kMaxN = 2e5 + 1;

struct E {
  int x, y, v;
  bool operator<(const E &_e) const {
    return x < _e.x;
  }
} e[kMaxN];
map<int, int> v;
int n, m, ans;

int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> e[i].x >> e[i].y;
  }
  sort(e + 1, e + 1 + m);
  v[n] = 1;
  for (int i = 1, j = 1; i <= m; i = j) {
    for (; e[i].x == e[j].x; j++) {
    }
    for (int k = i; k < j; k++) {
      e[k].v = v[e[k].y - 1] || v[e[k].y + 1];
    }
    for (int k = i; k < j; k++) {
      v[e[k].y] = e[k].v;
    }
  }
  for (auto i = v.begin(); i != v.end(); i++) {
    ans += i->second;
  }
  cout << ans;
  return 0;
}
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<time.h>
#include<deque>
#include<cstring>
#define ll long long
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pf push_front
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define M 5000005
#define endl "\n"
#define AC ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
void solve(){
    
}
map<ll,vector<ll> > black;
map<ll,bool> ex;
signed main(){
    AC;
    ll n,m;
    cin>>n>>m;
    FOR(i,0,m){
        ll x,y;
        cin>>x>>y;
        black[x].pb(y);
    }
    ex[n]=1;
    for(auto[a,b]:black){
        map<ll,bool> tmp,result;
        for(auto i:b){
            if(ex.find(i)!=ex.end()){
                tmp[i]=1;
                ex.erase(ex.find(i));
            }
        }
        //cout<<endl;
        for(auto i:b){
            if(tmp.find(i+1)!=tmp.end()) result[i]=1;
            if(tmp.find(i-1)!=tmp.end()) result[i]=1;
            if(ex.find(i+1)!=ex.end()) result[i]=1;
            if(ex.find(i-1)!=ex.end()) result[i]=1;
        }
        for(auto i:result) ex[i.F]=1;
        //cout<<"ex= ";
        //for(auto i:ex) cout<<i.F<<" ";
        //cout<<endl;
    }
    cout<<ex.size()<<endl;
}
