#include<bits/stdc++.h>
#define BOOM ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<setprecision(10);
#define NEWLINE cout<<'\n';
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define MOD  1000000007
#define mod  998244353
#define ff first
#define ss second
#define mset(a,b) memset(a, b, sizeof(a))
using namespace std;
#define MAXN 100005

int fastscan() 
{ 
	bool negative = false; 
	register int c; 
	int number = 0; 
	for(c = getchar(); !(c>47 && c<58) && c!= '-'; c= getchar()); 
	if (c=='-')  c = getchar(), negative = true; 
	for (; (c>47 && c<58); c=getchar())  number = (number<<1) + (number<<3) + (c ^ 48); 
	if (negative) return -number; 
	return number;
} 
int gcd(int a, int b) { if(!b) return a; return gcd(b,a%b); }
//LARGE POWERS
ll power(long long x, long long y, long long p)  
{  
	ll res = 1; 
	x = x % p; 
	if (x == 0) return 0;
	while (y > 0){  
		if (y & 1)  res = (res*x) % p;  
		y = y>>1; 
		x = (x*x) % p;  
	}  
	return res;  
} 
struct HASH {
    static uint64_t splitmix64(uint64_t x)  {
        x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);
    }
};
int N;
bool sortbyff(const pair<int,int> &a, const pair<int,int> &b)  { 
    if(a.ff!=b.ff)  return (a.ff<b.ff);
    return (abs(N - a.ss) > abs(N - b.ss)); 
} 
int main()
{	
	BOOM
	int  _=1, n, m, k, l=0, r=0, b, c, i, j, tt=1, t, sum=0,x,y,z=1;
	bool flag=0;
	// string s,ss;
	// tt = fastscan();
	// cin>>tt;
	// while(tt--){
	for(_=1;_<=tt;_++) {
		// int q;
		cin>>N>>m;
		// for(i=0;i<n;i++) cin>>a[i];
		int cur=0, sum=0, ans=0;
		pair<int,int> a[m];
		for(i=0;i<m;i++) cin>>a[i].ff>>a[i].ss;
			sort(a, a+m, sortbyff);
		// if(a[0].ff == n && )
		// cout<<"a = \n"; for(auto i:a) cout<<i.ff<<' '<<i.ss<<'\n'; NEWLINE
		unordered_map<int,pair<int,int>,HASH> w;
		set<int> s;
		s.insert(N); w[N] = {INT_MAX,0};
			// cout<<"set = "; for(int j:s) cout<<j<<' '; NEWLINE
		std::vector<int> v;
		for(i=0;i<m;i++) {
			if (s.count(a[i].ss - 1) > 0 && w.find(a[i].ss - 1) != w.end() && (w[a[i].ss - 1].ff < a[i].ff || w[a[i].ss - 1].ss < a[i].ff) || 
				s.count(a[i].ss + 1) > 0 && w.find(a[i].ss + 1) != w.end() && (w[a[i].ss + 1].ff < a[i].ff || w[a[i].ss + 1].ss < a[i].ff)) {
				s.insert(a[i].ss);
				if (w.find(a[i].ss) == w.end()) 
					w[a[i].ss] = { INT_MAX, a[i].ff };
				else
					w[a[i].ss] = { w[a[i].ss].ss, a[i].ff };
			}
			else
				// s.erase(a[i].ss), w.erase(a[i].ss);
				v.push_back(a[i].ss);

			if(i==n-1 || a[i+1].ff != a[i].ff)	{
				for(int x : v)
					s.erase(x), w.erase(x);
				v.clear();
			}

			// cout<<"set = "; for(int j:s) cout<<j<<' '; NEWLINE
		}
		// w.clear(); for(int i:s) w[i] = 1;
		cout<<s.size();
		// cout<<"dp = "; for(int i:dp) cout<<i<<' '; NEWLINE
		// cout<<*max_element(dp, dp+n);


		// cout<<"Case #"<<_<<": "<<ans<<'\n';
		// if(!flag)
			// cout<<-1<<'\n';
			// cout<<"YES"<<"\n";
		// else
			// cout<<"NO"<<"\n";
	}
	return 0;

}
#include <bits/stdc++.h>

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; for(int tt = 0; tt < t; ++tt)
#define sz(x) (int)(x).size()
#define sort_unique(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()));
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 800 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
/**
Read problem statement carefully
**/
int arr[N][N];

int n, k;
bool check(int mid, int L){
    vector<vector<int>> pre(n+1, vector<int>(n+1));
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1] + (arr[i-1][j-1] >= mid);

    bool ok = 1;
    for(int i = 0; i+k <= n; ++i){
        for(int j = 0; j+k <= n; ++j){
            int res = pre[i+k][j+k] - pre[i+k][j] - pre[i][j+k] + pre[i][j];
            if(res < L) ok = 0;
        }
    }
    return ok;
}

void solve(int T){
    int n, m;
    cin >> n >> m;
    map<int, vector<int>> mp;
    for(int i = 0, x, y; i < m; ++i){
        cin >> x >> y;
        mp[x].push_back(y);
    }
    
    set<int> st;
    st.insert(n);
    for(auto &[x, v]: mp){
        vector<int> add;
        for(auto &y: v){
            if(st.count(y-1) || st.count(y+1))
                add.push_back(y);
        }
        for(auto &y: v) st.erase(y);
        for(auto &y: add) st.insert(y);
    }

    cout << sz(st) << "\n";
}

int main()
{
    Fast;
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // louisfghbvc
        solve(1);
    return 0;
}

/**
Enjoy the problem.
**/
