// Problem: E - White Pawn
// Contest: AtCoder - AtCoder Beginner Contest 203（Sponsored by Panasonic）
// URL: https://atcoder.jp/contests/abc203/tasks/abc203_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Author: abhidot

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
using namespace std;
const long long N=200005, INF=2e9+5; //2000000000000000000;

#define debug(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
	cout << vars << " = ";
    string delim = "";
    (..., (cout << delim << values, delim = ", "));
    cout<<"\n";
}


int power(int a, int b, int p){
	if(a==0)
	return 0;
	int res=1;
	a%=p;
	while(b>0)
	{
		if(b&1)
		res=(res*a)%p;
		b>>=1;
		a=(a*a)%p;
	}
	return res;
}


void print(bool n){
    if(n){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
}


int32_t main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    vector<pii> p;
    vector<int> a, b;
    set<int>s;
    
    for(int i=0;i<m;i++){
    	int x,y;
    	cin>>x>>y;
    	p.pb({x,y});
    }
    s.insert(n);
    sort(all(p));
    
    int l=0;
    while(l<m){
    	int r=l;
    	a.clear();
    	b.clear();
    	while(r<m&&p[l].ff==p[r].ff) r++;
    	for(int i=l;i<r;i++){
    		int y = p[i].ss;
    		if((s.find(y-1)!=s.end()||s.find(y+1)!=s.end())&&s.find(y)==s.end()) a.pb(y);
    		if((s.find(y-1)==s.end()&&s.find(y+1)==s.end())&&s.find(y)!=s.end()) b.pb(y);
    	}
    	for(auto i:a) s.insert(i);
    	for(auto i:b) s.erase(i);
    	l=r;
    }
    
    cout<<s.size();
}
#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,s,e) for(int i=s ; i < e ; i++)
#define rrep(i,s,e) for(int i=s ; i > e ; i--)
#define srep(i,s,e,j) for(int i=s ; i < e ; i+=j)
#define tr(i,x) for(auto i : x)
#define vinp(a) for(int i=0 ; i<a.size() ; i++)cin>>a[i]
#define ainp(a,n) for(int i=0; i<n; i++)cin>>a[i]
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define vpi vector<pii>
#define maxpqi priority_queue<int>
#define minpqi priority_queue <int, vector<int>, greater<int> >
#define pii pair<int,int> 
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define pf push_front
#define endl '\n'
#define br printf("\n")
#define inf 1000000
#define imap map<int,int>   
#define uimap unordered_map<int,int>
#define gcd(a,b) __gcd(a,b)
#define mod 1000000007
#define clr(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define lb lower_bound
#define ub upper_bound
#define npos string::npos
#define all(x) x.begin(),x.end()
#define descen greater<int>()
// vector<vector<int>> v( n , vector<int> (m, 0));

//bitset<n>(x).to_string() -- return string // here n is bit length.
// x << y    ====   x*(2^y)
// x >> y    ====   x/(2^y)
// x&1 --- 1 then x is odd
/*
    lower_bound: iterator pointing to the first element which has a value not less than ‘val’.
    upper_bound: iterator pointing to the first element which has a value greater than ‘val’.
*/

// Driver function to sort the vector elements 
// by second element of pairs 
// -- IN ASCENDING ORDER --
bool comp(const pair<int,int> &a, const pair<int,int> &b){ 
    return (a.second < b.second); 
}

string yes="YES",no="NO";

void solve(){
    int tt = 1;
    // cin >> tt;
    while(tt--){
        int n,m;cin>>n>>m;
        map<int,vi>mat;
        set<int>avai;
        int x,y;
        rep(i,0,m){
            cin>>x>>y;
            mat[x].pb(y);
        }

        avai.insert(n);
        tr(i,mat){
            set<int>add;
            tr(j,mat[i.F]){
                if(avai.find(j-1) != avai.end() || avai.find(j+1) != avai.end()){
                    add.insert(j);
                }
            }
            tr(j,mat[i.F]){
                if(avai.find(j) != avai.end()){
                    avai.erase(j);
                }
            }
            tr(j,add)avai.insert(j);
        }
        cout << avai.size() << endl;
    }
}

int32_t main()
{
    fastio
    // ios::sync_with_stdio(false);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    solve();
    return 0;
}

/*
// Sort the array in descending order 
    sort(arr, arr + n, greater<int>()); 
*/