//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  map<int, vi> mp;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    y -= n;
    mp[x].emplace_back(y);
  }
  map<int, int> dp;
  dp[0] = 1;
  for(auto &[ig, v]:mp) {
    map<int, int> ch;
    for(auto z:v) {
      ch[z] = dp[z+1]|dp[z-1];
    }
    for(auto [z, val]:ch) dp[z] = val;
  }
  int ans = 0;
  for(auto [x, y]:dp) ans += y;
  cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define mod 1000000007
#define pb push_back
#define ss second
#define ff first
#define all(v) v.begin(), v.end()
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)


int32_t main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n,k;
    cin >> n >> k;
    vector<pair<int,int>> v(k);

    for(int i = 0; i < k; ++i)
        cin >> v[i].ff >> v[i].ss;

    sort(all(v));

    set<int> can;
    can.insert(n);

    for(int i = 0; i < k;) {
        vector<int> rem,add;
        int temp = v[i].ff;

        while(i < k && v[i].ff == temp) {
            int l = can.count(v[i].ss - 1);
            int r = can.count(v[i].ss + 1);

            if(l + r == 0)
                rem.push_back(v[i].ss);
            else add.pb(v[i].ss);

            i++;
        }

        for(int j: rem)
            can.erase(j);

        for(int j: add)
            can.insert(j);
    }

    cout << can.size();
    
    return 0;
}