#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int n,m;
  cin>>n>>m;
  map<int,vector<int>>mp;
  rep(i,m){
    int x,y;
    cin>>x>>y;
    mp[x].push_back(y);
  }
  set<int>s;
  s.insert(n);
  for(auto p:mp){
    vector<int>add;
    for(auto y:p.second){
      if(s.count(y-1)||s.count(y+1)){
        add.push_back(y);
      }
    }
    for(auto y:p.second){
      if(s.count(y)) s.erase(y);
    }
    for(auto y:add) s.insert(y);
  }
  cout<<s.size()<<endl;
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <string>
#include <sstream>
#include <iomanip>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, n) FOR(i,0,n)
#define irep(i, n) IFOR(i,0,n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;

using namespace std;

int main() {
    
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        --a;
        ans += (ll)(b * (b + 1) / 2) - (a * (a + 1) / 2);
    }
    cout << ans << endl;
    return 0;
}
