#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define rep1(i,n) for(int i = 1 ; i <= (n) ; i++)
#define rrep(i,n) for(int i = (n) - 1 ; i >= 0 ; i--)
#define rrep1(i,n) for(int i = (n) ; i > 0 ; i--)
#define MOD 1000000007
using ll = int64_t;
using P = pair<int, int>;
using PL = pair<ll,ll>;
using PD = pair<double,double>;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vP = vector<P>;
using p_q = priority_queue<int, vi, greater<int>>;
const int INF = 1001001001;
const ll LINF = (1ll<<62) + ((1ll<<62)-1);
#define v(n) vector<n>
#define vv(n) vector<vector<n>>
#define vvv(n) vector<vector<vector<n>>>
#define p_q(n) priority_queue<(n), v(n), greater<n>>
#define line cout << "================================" << endl;
#define Yn(x) ((x) ? "Yes" : "No")
#define yn(x) ((x) ? "yes" : "no")
#define mmax(a,b) a = max(a,b)
#define mmin(a,b) a = min(a,b)
#define debug(x) cout << #x" : " << (x) << endl;
#define output(x) cout << (x) << endl;
#define outs(x) cout << #x << endl;
#define mod(n) %(n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
template <typename T> void chmin(T& a, T b){if(a>b)a=b;}
template <typename T> void chmax(T& a, T b){if(a<b)a=b;}

class alucrex{
    public:
    void vin(vi& a){rep(i,a.size())cin>>a[i];}
    void vin1(vi& a){rep1(i,a.size())cin>>a[i];}
    void vvin(vvi& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];}
    void vvdes(vvi& a){rep(i,a.size()){rep(j,a[i].size()){
        cout << a[i][j] << " ";}cout<<endl;
    }}
    void vinl(vl& a){rep(i,a.size())cin>>a[i];}
    void vvinl(vvl& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];}
    void vvdesl(vvl& a){rep(i,a.size()){rep(j,a[i].size()){
        cout << a[i][j] << " ";}cout<<endl;
    }}
    void vpin(vP& a){for(auto& x:a)cin>>x.first>>x.second;}
    template<typename T>
    void vvd(vv(T)& a){rep(i,a.size()){rep(j,a[i].size()){
        cout << a[i][j] << " ";}cout<<endl;
    }}
};
#include <chrono>
using namespace chrono;


int main(){
    alucrex al;
    steady_clock::time_point start = steady_clock::now();
    map<int, vi> mp;
    int n, m; cin >> n >> m;
    rep(i,m) {
        int x, y; cin >> x >> y;
        mp[x].push_back(y);
    }
    set<int> table;
    table.insert(n);

    for(auto i : mp) {
        vi erase, add;
        for(int j : i.second) {
            int flag = 0;
            if(table.count(j - 1) || table.count(j + 1)) add.push_back(j);
            else if(table.count(j)) erase.push_back(j);
        }
        for(int j : add) table.insert(j);
        for(int j : erase) table.erase(j);
    }
    cout << table.size() << endl; 
    steady_clock::time_point end = steady_clock::now();
    auto res = end - start;
    //cout << "実行時間：" << duration_cast<milliseconds>(res).count() << "ms" << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main() 
{
    int n;
    cin >> n;
    set<int> s;
    s.emplace(n);
    int m;
    cin >> m;
    map<int, vector<int>> mp;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        mp[x].push_back(y);
    }
    for(auto [x, v] : mp) {
        sort(v.begin(), v.end());
        vector<int> add;
        vector<int> er;
        for(auto e : v) {
            if(s.count(e)) {
                if(!s.count(e - 1) and !s.count(e + 1)) er.push_back(e);
            } else {
                if(s.count(e - 1) or s.count(e + 1)) add.push_back(e);
            }
        }
        for(auto e : add) s.emplace(e);
        for(auto e : er) s.erase(e);
    }
    cout << s.size() << endl;
}