#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")

#define ll long long
#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(unordered_set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif
template<typename T> void print(T && x) {cout << x << "\n";}
template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);}

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
const int maxn=200005;

//i_am_noob
//#define wiwihorz  
int n,m;
pii a[maxn];
map<int,vector<int>> mm;
set<int> st;

void orzck(){
    cin >> n >> m;
    rep(m){
        int x,y;
        cin >> x >> y;
        mm[x].pb(y);
    }
    st.insert(n);
    for(auto p: mm){
        vector<int> vec=p.second;
        set<int> st1,st2;
        for(auto i: vec){
            if(st.count(i-1)||st.count(i+1)) st1.insert(i);
            else st2.insert(i);
        }
        for(auto i: st1) st.insert(i);
        for(auto i: st2) st.erase(i);
    }
    print(sz(st));
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    #ifdef i_am_noob
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    freopen("output2.txt","w",stderr);
    #endif
    cout << fixed << setprecision(15);
    int t;
    #ifdef wiwihorz
    cin >> t;
    #else
    t=1;
    #endif
    while(t--) orzck();
    return 0;
}
#include<bits/stdc++.h>
#define db double
#define reg register
#define LL long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ull unsigned long long
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=head[a];i;i=e[i].nxt)


using namespace std;
bool Handsome;
inline void Mi(int &x,int y){if(x>y && (x=y));}
inline void Mx(int &x,int y){if(x<y && (x=y));}
const int M=4e5+5;
int n,m,x[M],y[M],c[M],cnt;
vector<int> g[M];
bool vis[M],p[M];
int ID(int x){
	return x-n+m;
}
bool check(int x){
	if(x<0 || x>(m<<1))return 0;
	return 1;
}
bool Most;
int main(){
//	printf("%.2lfMB\n",(&Most-&Handsome)/1024.0/1024.0);
	scanf("%d%d",&n,&m);
	rep(i,1,m)scanf("%d%d",&x[i],&y[i]),c[i]=x[i];
	sort(c+1,c+m+1);cnt=unique(c+1,c+m+1)-c-1;
	rep(i,1,m)g[lb(c+1,c+cnt+1,x[i])-c].pb(y[i]);
	rep(i,1,cnt)sort(g[i].begin(),g[i].end());
	vis[m]=1;
	rep(i,1,cnt){
		rep(j,0,g[i].size()-1){
			int x=ID(g[i][j]);
			if(!check(x))continue;
			if(check(x-1) && vis[x-1])p[x]=1;
			if(check(x+1) && vis[x+1])p[x]=1;
		}
		rep(j,0,g[i].size()-1){
			int x=ID(g[i][j]);
			if(!check(x))continue;
			vis[x]=p[x];p[x]=0;
		}
	}
	int ans=0;
	rep(i,0,m<<1)ans+=vis[i];
	printf("%d\n",ans);
	return 0;
}