#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll md = 998244353;
const ll OO = 1e16;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
 
int ad(ll a, ll b) {
    return (a+b+md) % md;
}
 
int ml(ll a, ll b) {
    return ((a%md) * (b%md)) % md;
}
 
ll n, m;
const int N = 2e5 + 4;
pair<ll,ll> a[N+1];
ll dp[N+1];
 
void set_dp() {
    for(int i=0; i<N; ++i)
        dp[i] = -1;
}
 
int upperbound(int lo, int hi, pair<ll,ll> K) {
    while (lo < hi) {
        int mid = (lo + hi + 1) >> 1;
        if (a[mid].first < K.first) {
            lo = mid + 1;
        } else if (a[mid].first > K.first) {
            hi = mid - 1;
        } else {
            if (a[mid].second <= K.second) {
                lo = mid;
            } else {
                hi = mid-1;
            }
        }
    }
    if (lo > hi) return -1;
    if (a[lo].first != K.first || a[lo].second > K.second) return -1;
    return lo;
}
 
ll reach(int idx) {
    if (a[idx].first == n && a[idx].second == 0) return 1;
    ll &ans = dp[idx];
    if (ans != -1) return ans;
    ans = 0;
    int i = upperbound(0, idx-1, {a[idx].first-1, a[idx].second-1});
    if (i >= 0 && i < m)
        ans += reach(i);
    i = upperbound(idx+1, m-1, {a[idx].first+1, a[idx].second-1});
    if (i >= 0 && i < m)
        ans += reach(i);
    return ans = ans > 0;
}
 
int main() {
    FAST_IO;

    set_dp();
    cin >> n >> m;
    for (int i=0; i<m; ++i) {
        cin >> a[i].second >> a[i].first;
    }
    a[m] = {n,0};
    ++m;
    sort(a, a + m);
    ll ans = 0;
    for(int i=0; i<m-1; ++i) {
        if (a[i].first != a[i+1].first && reach(i) > 0)
            ans++;
    }
    if (reach(m-1) > 0) ans++;
    cout << ans << "\n";
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define pob pop_back
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vll vector<long long int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define mod2 998244353
#define ll long long int
#define ld long double
#define pi 3.141592653589793238
#define Endl endl
#define endl "\n"
const int N = 2e5 + 15;
const ll inf = 1e18;

void solve()
{
        ll n , m;
        cin >> n >> m;
        map<ll,set<ll>> mp;
        for(ll i=1;i<=m;i++)
        {
                ll r , c;
                cin >> r >> c;
                mp[r].insert(c);
        }
        set<ll> ans = {n};
        for(auto x:mp)
        {
                set<ll> good;
                set<ll> bad;
                for(auto y:x.S)
                {
                        if(ans.count(y-1) or ans.count(y+1))
                                good.insert(y);
                        else
                                bad.insert(y);
                }
                for(auto y:good)
                        ans.insert(y);
                for(auto y:bad)
                        ans.erase(y);
        }
        cout << ans.size();
}         

void debug(ll tt) {}
 
signed main()
{
        FAST;
        int t = 1;
        // cin >> t;
        while(t--)
        {
                solve();
        }
}