#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <map>
#include <set>
#include <vector>

int main(){
    int N, M;
    scanf("%d %d", &N, &M);

    std::map<int, std::vector<int>> Map;
    for(int i = 0; i < M; i++){
        int X, Y;
        scanf("%d %d", &X, &Y);
        Map[X].emplace_back(Y);
    }

    std::set<int> Set{N};
    for(auto [key, Vec] : Map){
        std::set<int> SetIn, SetOut;
        for(int y : Vec){
            if(Set.find(y - 1) != Set.find(y + 1)) SetIn.insert(y);
            else SetOut.insert(y);
        }
        for(int in : SetIn) Set.insert(in);
        for(int out : SetOut) Set.erase(out);
    }

    printf("%d\n", (int)Set.size());
    
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define int long long
using ll = long long;
using P = pair<int,int>;

int n,m;

signed main(){
  cin >> n >> m ;
  
  map<int,int> cnt;
  vector<P> p(m);
  for(int i=0;i<m;i++){
    cin >> p[i].first;
    cin >> p[i].second;
    cnt[p[i].first]++;
  }
  
  sort(p.begin(),p.end());
  
  //for(int i=0;i<m;i++){
  //  cout << "i=" << i << ":" << p[i].first << "," << p[i].second << endl;
  //}
  
  vector<int> d(2*m+1,0);
  
  d[m] = 1;
  
  int j = 0;
  map<int,int> manip;
  for(auto it = cnt.begin(); it != cnt.end(); it++){
    int v = it->first;
    // cout << "it->first=" << it->first << endl;
    // int c = it->second;
    manip.clear();
    int j2 = j;
    while( p[j].first == v ){
      int y = p[j].second;    // n座標系
      int y2 = ( y - n ) + m; // m座標系
      if( y2 >= 0 && y2 <= 2*m ){
        manip[y2] = 0;
      }
      j++;
    }
    j = j2;
    while( p[j].first == v ){
      int y = p[j].second;     //
      int y2 = ( y - n ) + m;  // m
      if( y2 >= 0 && y2 <= 2*m && y2-1 >= 0 && y-1>=0 && d[y2-1]==1 ){
        manip[y2]=1;
      }
      if( y2 >= 0 && y2 <= 2*m && y2+1 <=2*m && y+1<=2*n && d[y2+1]==1 ){
        manip[y2]=1;
      }
      j++;
    }
    for(auto x: manip){
      d[x.first] = x.second;
    }
    //for(int j=0;j<2*m+1;j++){
    //  cout << "," << d[j];
    //}
    //cout << endl;
  }
  int res = 0;
  for(int i=0;i<=2*m;i++){
    if(d[i]!=0) res++;
  }
  cout << res << endl;
  
}

