#include<bits/stdc++.h>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.bigin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>

using namespace std;

int main(){
    int n, m, ans = 0;
    cin >> n >> m;
    int Max = 1, Min = n;
    Srep(m){
        int l,r;
        cin >> l >> r;
        Max = max(l,Max);
        Min = min(r,Min);
    }
  	if(Min - Max < 0) ans = 0;
  	else ans = Min - Max + 1;
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<ll> sum(n), b(n);
    rep(i,n){
        ll ai, bi;
        cin >> ai >> bi;
        sum[i] = ai + bi;
        b[i] = bi;
    }
    sort(rall(sum));
    ll sumAB = 0, sumB = 0;
    rep(i,n){
        if (i % 2  == 0) sumAB += sum[i];
        sumB += b[i];
    }
    cout << sumAB-sumB << endl;
    return 0;
}