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

const double pi=3.141592653589793;
const int64_t inf=1L<<60;
//const int64_t mod=1000000007;
const int64_t mod=998244353;

int main(){
  int N,M;
  cin>>N>>M;
  map<int,set<int>> black;
  set<int> move;
  move.insert(N);
  for(int i=0; i<M; i++){
    int x,y;
    cin>>x>>y;
    black[x].insert(y);
  }
  set<int> pushlist;
  set<int> poplist;
  for(auto m : black){
    auto ylist=m.second;
    for(int y : ylist){
      if(move.count(y)){
        if(!move.count(y+1)&&!move.count(y-1)){ //隣がいけないならダメ
          poplist.insert(y);
        }
      }
      else{
        if(move.count(y+1)||move.count(y-1)){ //隣がいけるならok
          pushlist.insert(y);
        }
      }
    }
    for(int i : poplist){
      move.erase(i);
      poplist.erase(i);
    }
    for(int i : pushlist){
      move.insert(i);
      pushlist.erase(i);
    }
  }
  cout<<move.size()<<endl;
}
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
	T t=0;
	char k;
	bool vis=0;
	do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
	while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
	return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
int s,n;
pair<int,int>a[200005];
map<int,queue<int> >ma;
map<int,bool>h;
int vis[200005],ans;
vector<int>G[200005];
void dfs(int n){
	if(vis[n]==2)return;
	ans+=vis[n];
	for(auto i:G[n])dfs(i);
	vis[n]=2;
}
int main(){
	n=read,s=read;
	a[0]=make_pair(0,n);
	for(int i=1;i<=s;++i)
		a[i].first=read,a[i].second=read;
	sort(a+1,a+s+1);
	for(int i=s;~i;--i)
		if(h[a[i].second]){
			queue<int>&w=ma[a[i].second];
			while(w.size()&&a[w.front()].first>a[i].first)G[i].push_back(w.front()),w.pop();
			ma[a[i].second-1].push(i);
			ma[a[i].second+1].push(i);
		}else{
			h[a[i].second]=1;vis[i]=1;
			queue<int>&w=ma[a[i].second];
			while(w.size()&&a[w.front()].first>a[i].first)G[i].push_back(w.front()),w.pop();
			ma[a[i].second-1].push(i);
			ma[a[i].second+1].push(i);
		}
	dfs(0);cout<<ans;
	return 0;
}