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

// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;

int n, m, x, y;
map<int,vector<int>> black;

int main() {
    cin >> n >> m;
    rep(i,m) {
        cin >> x >> y;
        black[x].push_back(y); 
    }

    set<int> possible{n};
    for (auto [x, ys] : black) {
        vector<int> add;

        for (auto y : ys) {
            if (possible.count(y+1)) add.push_back(y);
            if (possible.count(y-1)) add.push_back(y);
        }

        for (auto y : ys) possible.erase(y);
        for (auto y : add) possible.insert(y);       
    }
    cout << possible.size() << "\n";
}
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define double long double
#define rbtree __gnu_pbds::tree<int,__gnu_pbds::null_type,less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
#define int ll
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define ALL(X) X.begin(),X.end()
#define F(i,n)  FF(i,0,n)
#define F1(i,n)  FF(i,1,n+1)
#define FF(i,n,m) for(int i=(int)n;i<(int)m;++i)
#ifndef LOCAL
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#else
#endif // LOCOL
//#define mp make_pair
using namespace std;
//using namespace __gnu_pbds;
template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;}
template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;}
inline ostream& operator << (ostream& os,__int128_t a){if(a==0) {return (os<<'0');}bool flag=0;if(a<0) {a=-a,flag=1;}string s;while(a){s+=a%10+'0';a/=10;}s+=flag?"-":"";reverse(ALL(s));return os<<s;}
inline istream& operator >>(istream& is,__int128_t& a){string s;cin>>s;a=0;for(auto c:s) a=a*__int128_t(10)+__int128_t(c-'0');return is;}
template<typename T,typename P> inline ostream& operator << (ostream& os,pair<T,P> a){os<<a.first<<" "<<a.second; return os;}
template<typename T,typename P> inline istream& operator >> (istream& is,pair<T,P> &a){is>>a.first>>a.second; return is;}
using ll=long long;
using ull=unsigned long long;
using int128= __int128_t;
using uint128= __uint128_t;
using pii =pair<int,int>;
const double pi=acos(-1);
const int N=800+5;
const ll M=1000000000;
const ll INF_64=0x3f3f3f3f3f3f3f3f;
const int INF_32=0x3f3f3f3f;
const int16_t INF_16=0x3f3f;
const int klog=20;
const int mod=998244353;//1E9+7
const double eps=1E-8;

void gen(){

}
void sol(){
    int n,m;
    cin>>n>>m;
    vector<pii> a(m);
    F(i,m){
        cin>>a[i].first>>a[i].second;
    }
    sort(ALL(a),[](auto&l,auto&r){return l.first<r.first;});
    map<int,int> dp;
    dp[n]=1;
    vector<pii> upd;
    F(t,m){
        if(t!=0&&a[t].first!=a[t-1].first){
            while(upd.size()){
                auto p=upd.back();upd.pop_back();
                dp[p.first]=p.second;
            }
        }
        int x=a[t].first,y=a[t].second;
        int tmp=0;
        if(y-1>=0) tmp+=dp[y-1];
        if(y+1<=2*n) tmp+=dp[y+1];
        upd.pb({y,tmp>0?1:0});
    }
    for(auto &p:upd){
        dp[p.first]=p.second;
    }
    upd.clear();
    int an=0;
    for(auto &[x,y]:dp) if(y!=0) an++;
    cout<<an<<"\n";
}
int32_t main(){
    #ifdef LOCAL
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    #endif // LOCAL
    IOS;
    int t=1;
    gen();
    //cin>>t;
    FF(i,1,t+1){
        //cout<<"Case #"<<i<<": ";
        sol();
    }
}
