#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

#ifdef LOCAL
#define log(val) std::cerr << std::setw(3) << __LINE__ << "| " << #val << " = " << (val) << std::endl
#define dbg(proc) proc
#else
#define log(val) 0
#define dbg(proc) 0
#endif

template <typename T>
std::ostream& operator<<(std::ostream& os,const std::vector<T>& v){os << "{";if(!v.empty()){os << v[0];for(std::size_t i=1;i<v.size();++i){os << ", " << v[i];}}return os << "}";}

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, M;
P YX[200100];
std::set<int> se;

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int X, Y;
        std::cin >> X >> Y;

        YX[i] = std::make_tuple(X, Y);
    }

    std::sort(YX, YX + M);

    se.emplace(N);

    for(int i=0,j=0;i<M;){
        while(j < M && fst(YX[j]) == fst(YX[i])){
            j += 1;
        }

        std::set<int> ok, ng;

        while(i < j){
            auto [Y, X] = YX[i];

            if(se.count(X) > 0){
                ng.emplace(X);
            }

            if(se.count(X - 1) > 0 || se.count(X + 1) > 0){
                ok.emplace(X);
            }
            
            i += 1;
        }

        for(int x : ng){
            auto it = se.find(x);

            if(it != se.end()){
                se.erase(it);
            }
        }

        for(int x : ok){
            se.emplace(x);
        }
    }

    int res = se.size();
    std::cout << res << std::endl;
}

#include <bits/stdc++.h>
using namespace std;

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N = 4e5+10;

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int npos, npawns; cin >> npos >> npawns;
	map<int,vector<int>> mp;
	fr(i,npawns){
		int x, y; cin >> x >> y;
		mp[x].push_back(y);
	}
	set<int> at;
	at.insert(npos);
	for(auto &[x,v] : mp){
		vector<int> por, tirar;
		for(auto &i : v){
			tirar.push_back(i);
			if(at.count(i-1) or at.count(i+1)) por.push_back(i);
		}
		for(auto &i : tirar) at.erase(i);
		for(auto &i : por) at.insert(i);
	}
	cout << sz(at) << "\n";
}