#include <bits/stdc++.h>

using namespace std;

//begin of def

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define endl '\n'

using lli = long long int;
using ulli = unsigned long long int;
using Ld = long double;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using pld = pair<Ld, Ld>;
#define X first
#define Y second

#define rep(I, S, E) for(int I = (S); I < (E); I++)
#define repq(I, S, E) for(int I = (S); I <= (E); I++)

#define pb push_back
#define epb emplace_back

#define ALL(X) X.begin(), X.end()

//end of def

int main(){
    fastio;
    lli n;
    int m;
    cin >> n >> m;
    vector<pii> v(m);
    rep(i, 0, m)
        cin >> v[i].X >> v[i].Y;
    sort(ALL(v));
    set<lli> st;
    st.insert(n);
    lli nw = -2, er = -2;
    rep(i, 0, m){
        if(i && v[i].X != v[i - 1].X)
            nw = er = -2;
        int t = er;
        if(st.count(v[i].Y))
            er = v[i].Y;
        st.erase(v[i].Y);
        if((st.count(v[i].Y - 1) && nw != v[i].Y - 1) || st.count(v[i].Y + 1) || t == v[i].Y - 1){
            if(st.count(v[i].Y) == 0)
                nw = v[i].Y;
            st.insert(v[i].Y);
        }
    }
    cout << st.size();
    return 0;
}

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> X(M), Y(M);
	for (int i = 0; i < M; ++i) {
		cin >> X[i] >> Y[i];
	}
	vector<pair<int, int> > points;
	points.push_back(make_pair(0, N));
	for (int i = 0; i < M; ++i) {
		points.push_back(make_pair(X[i], Y[i]));
		points.push_back(make_pair(X[i] - 1, Y[i] - 1));
		points.push_back(make_pair(X[i] - 1, Y[i] + 1));
	}
	sort(points.begin(), points.end());
	points.erase(unique(points.begin(), points.end()), points.end());
	int S = points.size();
	vector<vector<int> > G(S);
	for (int i = 0; i < M; ++i) {
		int ptr1 = lower_bound(points.begin(), points.end(), make_pair(X[i] - 1, Y[i] - 1)) - points.begin();
		if (ptr1 != S && points[ptr1] == make_pair(X[i] - 1, Y[i] - 1)) {
			G[ptr1].push_back(lower_bound(points.begin(), points.end(), make_pair(X[i], Y[i])) - points.begin());
		}
		int ptr2 = lower_bound(points.begin(), points.end(), make_pair(X[i] - 1, Y[i] + 1)) - points.begin();
		if (ptr2 != S && points[ptr2] == make_pair(X[i] - 1, Y[i] + 1)) {
			G[ptr2].push_back(lower_bound(points.begin(), points.end(), make_pair(X[i], Y[i])) - points.begin());
		}
	}
	map<int, vector<pair<int, int> > > y_axis;
	for (int i = 0; i < S; ++i) {
		y_axis[points[i].second].push_back(make_pair(points[i].first, i));
	}
	set<pair<int, int> > pawns;
	for (int i = 0; i < M; ++i) {
		pawns.insert(make_pair(X[i], Y[i]));
	}
	for (pair<int, vector<pair<int, int> > > i : y_axis) {
		vector<pair<int, int> > v = i.second;
		sort(v.begin(), v.end());
		for (int i = 0; i < int(v.size()) - 1; ++i) {
			if (pawns.find(points[v[i + 1].second]) == pawns.end()) {
				G[v[i].second].push_back(v[i + 1].second);
			}
		}
	}
	int ini = lower_bound(points.begin(), points.end(), make_pair(0, N)) - points.begin();
	queue<int> que;
	que.push(ini);
	vector<bool> vis(S, false);
	vis[ini] = true;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i : G[u]) {
			if (!vis[i]) {
				vis[i] = true;
				que.push(i);
			}
		}
	}
	int ans = 0;
	for (pair<int, vector<pair<int, int> > > i : y_axis) {
		if (vis[i.second.back().second]) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}