//#pragma GCC target("avx2")
//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define lc(x) ((x)<<1)
#define rc(x) (((x)<<1)|1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;

const ll MOD=1e9+7;
const ll LINF=1e18;
const int INF=0x3f3f3f3f;
const int MAXE=5000050;
const int MAXN=200050;
const int bk_sz=3420;
mt19937 rnd(114514);

map<int,int> visp;
pair<int,int> a[MAXN];
bool vis[MAXN];
void mainwork(int T){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&a[i].first,&a[i].second);
    }
    sort(a+1,a+m+1);
    visp[n]=1;
    for(int i=1,j=1;i<=m;i=j){
        while(a[i].first==a[j].first)j++;
        for(int k=i;k<j;k++){
            vis[k]=visp[a[k].second-1]||visp[a[k].second+1];
        }
        for(int k=i;k<j;k++){
            visp[a[k].second]=vis[k];
        }
    }
    int ans=0;
    for(auto i:visp){
        ans+=i.second;
    }
    printf("%d\n",ans);
}
signed main(){
    //IOS;
#ifndef ONLINE_JUDGE
    freopen("Ranulx.in","r",stdin);
    freopen("Ranulx.out","w",stdout);
#endif
    int t=1;
    //scanf("%d",&t);
    for(int i=1;i<=t;i++){
        mainwork(i);
    }
}
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
ll mod=1000000007;
ll INF = 100000000000000000;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}

ll fastExp(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x);
        x=((x)*(x));
        n=n/2;
    }
    return (result);
}

bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}

ll n,k;
map<ll,set<ll> > rows;
map<ll,set<ll> > cols;
vector<pll> v(200005);
map<pll,ll> dp;
set<ll> res;


void recur(ll sx,ll sy)
{
     if(dp.find({sx,sy})!=dp.end())
          return ;
     
     
     dp[{sx,sy}]=1;
     ll block=INF;
     if(cols[sy].upper_bound(sx)==cols[sy].end())
          res.insert(sy);
     else 
     {
          block=*cols[sy].upper_bound(sx);
     }
     // cout<<sx<<" "<<sy<<" "<<block<<"\n";
     auto it=cols[sy-1].upper_bound(sx);
     for( ; it!=cols[sy-1].end();it++)
     {
          if(*it<=block)
               recur(*it,sy-1);
          else 
               break;
     }
     it = cols[sy+1].upper_bound(sx);
     for( ; it!=cols[sy+1].end();it++)
     {
          if(*it<=block)
               recur(*it,sy+1);
          else 
               break;
     }

}


void solve()
{
     cin>>n>>k;
     ll i,j;
     for(i=0;i<k;i++)
          cin>>v[i].F>>v[i].S;

     for(i=0;i<k;i++)
     {
          rows[v[i].F].insert(v[i].S);
          cols[v[i].S].insert(v[i].F);
     }
     recur(0,n);
     cout<<res.size();
}


int main()
{

     ios;
     int t;
     // cin>>t;
     t=1;
     while(t--)
          solve();
     
     
}