
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x.size()))
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for(int i = (l); i < (r); ++i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-------
int n, m;
vector<array<int, 2>> black;
bool qry(int x, int y, int l, int r) {
	array<int, 2> target = {x, y};
	int it = lower_bound(black.begin() + l, black.begin() + r, target) - black.begin();
	if (it < r && black[it] == target) 
		return 1;
	return 0;
}
void pb(vector<array<int, 2>> & tmp, int l, int r) {
	array<int, 2> it = {l, r};
	while(sz(tmp) && it[0] <= tmp.back()[1]) {
		it[0] = min(tmp.back()[0], it[0]);
		tmp.pop_back();
	}
	tmp.pb(it);
}
int main() {
	scanf("%d%d", &n, &m);
	black.resize(m);
	for(auto &it : black) scanf("%d%d", &it[0], &it[1]);
	sort(all(black));
	set<int> point; point.insert(n);
	for(int l = 0, r = 0; l < m; l = r) {
		while(r < m && black[r][0] == black[l][0]) r++;
		vi diff;
		rep(i, l, r) {
			int blk = black[i][1];
			if (point.count(blk)) {
				if (!point.count(blk - 1) && !point.count(blk + 1)) {
					diff.pb(blk);
				}
			} else {
				if (point.count(blk - 1) || point.count(blk + 1)) {
					diff.pb(blk);
				}
			}
		}
		for(auto &p : diff) {
			if (point.count(p)) point.erase(p);
			else point.insert(p);
		}
	}
	printf("%d\n", sz(point));
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T> void print(T& v){ for(auto it : v) cout << it << " "; cout << endl; }
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, m;
    cin >> n >> m;
    vector<pii> v(m);
    FOR(i, m) cin >> v[i].first >> v[i].second;
    map<int, vi> H;
    FOR(i, v.size())
        H[v[i].first].push_back(v[i].second);

    set<int> S;
    S.insert(n);
    for(auto it : H){
        vi& tocheck = it.second;
        vi torem, toadd;
        for(auto it : tocheck)
            if (!S.count(it-1) && !S.count(it+1))
                torem.push_back(it);
            else
                toadd.push_back(it);
        for(auto it : torem)
            S.erase(it);
        for(auto it : toadd)
            S.insert(it);
    }
    cout << S.size() << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

