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

typedef long long ll;

int n, m;
ll x, y;
map<ll, vector<ll>> mp;
set<ll> s;
ll in[200005];
ll out[200005];
int cnt1, cnt2;

int main()
{
    cin>>n>>m;
    for (int i=1; i<=m; ++i)
    {
        cin>>x>>y;
        mp[x].push_back(y);
    }
    s.insert(n);
    for (auto t : mp)
    {
        cnt1 = 0;
        cnt2 = 0;
        for (auto it : t.second)
        {
            if (s.count(it)) out[++cnt2] = it;
            if (it-1>=0 && s.count(it-1)) in[++cnt1] = it;
            if (it+1<=2*n-1 && s.count(it+1)) in[++cnt1] = it;
        }
        for (int i=1; i<=cnt2; ++i) s.erase(out[i]);
        for (int i=1; i<=cnt1; ++i) s.insert(in[i]);
    }
    cout<<s.size();

    return 0;
}

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

#define debug(x) cout << #x << " is " << x << endl
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;

int n, m;
vector<P> p;

int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	int x, y;
	for (int i = 0; i < m; ++i) {
 		cin >> x >> y;
 		p.push_back({x, y});
	}
	sort(p.begin(), p.end());
	set<int> s;
	s.insert(n);
	int l = 0;
	while (l < m) {
		vector<int> a, b;
		int r = l;
		while (r < m) {
			if (p[r].first == p[l].first) r++;
			else break;
		}
		for (int i = l; i < r; ++i) {
			int y = p[i].second;
			if ((s.find(y - 1) != s.end() || s.find(y + 1) != s.end()) && s.find(y) == s.end()) a.push_back(y);
			if ((s.find(y - 1) == s.end() && s.find(y + 1) == s.end()) && s.find(y) != s.end()) b.push_back(y);
		}
		for (int e : a) s.insert(e);
		for (int e : b) s.erase(e);
		l = r;
	}
	cout << (int)s.size() << '\n';
	return 0;
}