#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <functional>
#include <queue>
#include <set>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

void boolflip(bool &a){
    a = !a ;
    return ;
}


int main(){
    int64_t n,m ;
    cin >> n >> m ;
    set<int> can ;
    can.insert(n) ;
    vector<pair<int,int> > black(m,pair<int,int>()) ;
    int x,y ;
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y ;
        black.at(i) = make_pair(x,y) ;
    }
    sort(black.begin(),black.end()) ;
    int j = 0 ;
    int nowx ;
    if (j < m)
    {
        nowx = black.at(j).first ;
    }
    
    

    while (j < m)
    {
        vector<int> next(0) ;
        while(j < m){
            if (black.at(j).first == nowx)
            {
                next.push_back(black.at(j).second) ;
            }else
            {
                break ;
            }
            j ++ ;
            
        }
        set<int> ok ;
        set<int> stop ;
        for (int i = 0; i < next.size(); i++)
        {
            int t = next.at(i) ;
            if (t == 0)
            {
                if (can.count(t+1))
                {
                    ok.insert(t) ;
                }
                
            }else if (t == 2*n)
            {
                if (can.count(t-1))
                {
                    ok.insert(t) ;
                }
            }else
            {
                if (can.count(t+1) || can.count(t-1))
                {
                    ok.insert(t) ;
                }
                
            }
            
            
            
            
        }
        for (int i = 0; i < next.size(); i++)
        {
           int t = next.at(i) ;
           if (can.count(t))
           {
               if (ok.count(t) == 0)
               {
                   stop.insert(t) ;
               }
               
               
           }
           
        }
        for(set<int>::iterator itr = ok.begin(); itr != ok.end(); ++itr) {
            can.insert(*itr) ;
        }
        for(set<int>::iterator itr = stop.begin(); itr != stop.end(); ++itr) {
            can.erase(*itr) ;
        }
        if (j < m)
        {
            nowx = black.at(j).first ;
        }
        
    }
    
    
    cout << can.size() << endl;
    
    
}
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 998244353;
const int INF = 1e18;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

signed main(){
  int A, B;
  cin >> A >> B;
  int C = 2*A+100;
  if( B < C ) cout << C-B << endl;
  else cout << 0 << endl;
}
