#include<bits/stdc++.h>
#define M 200005
typedef long long ll;
using namespace std;
bool f2;
char IO;
ll rd(){
	ll num=0;bool f=0;
	while(IO=getchar(),IO<48||IO>57)if(IO=='-')f=1;
	do num=(num<<1)+(num<<3)+(IO^48);
	while(IO=getchar(),IO>=48&&IO<=57);
	return f?-num:num;
}
int n,m;
struct node{
	int X,Y;
	bool operator<(const node &_)const{
		if(X==_.X)return Y<_.Y;
		return X<_.X;
	}
}A[M];
int B[M];
map<int,int> mp;
int upd[M],del[M],cnt,c;
bool f1;
int main(){
//	cout<<(&f1-&f2)/1024.0/1024.0<<endl;
	n=rd();m=rd();
	for(int i=1;i<=m;++i)
		A[i].X=rd(),A[i].Y=rd();
	sort(A+1,A+m+1);
	mp[n]=1;
	for(int i=1;i<=m;++i){
		if(mp[A[i].Y-1]||mp[A[i].Y+1])
			upd[++cnt]=A[i].Y;
		del[++c]=A[i].Y;
		if(i==m||A[i].X!=A[i+1].X){
			while(c)mp[del[c--]]=0;
			while(cnt)mp[upd[cnt--]]=1;
		}
	}
	int ans=mp[n];mp[n]=0;
	for(int i=1;i<=m;++i){
		ans+=mp[A[i].Y];
		mp[A[i].Y]=0;
	}cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main(){
  	int n, m;
  	cin >> n >> m;
  	map<int, vector<int>> mp;
  	rep(i, m){
    	int x, y;
      	cin >> x >> y;
      	mp[x].push_back(y);
    }
  
  	set<int> s;
  	s.insert(n);
  	for(auto p : mp){
      	vector<int> add;
    	for(int y : p.second){
        	if(s.count(y-1) || s.count(y+1)) add.push_back(y);
        }
        
        for(int y : p.second) s.erase(y);
        for(int y : add) s.insert(y);
    }
              
    cout << s.size() << endl;
}