#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <chrono>
#include<map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef unsigned int ui;
typedef unsigned short us;
typedef unsigned long long ull;

using namespace std;


int inputValue() {
  int a;
  scanf("%d", &a);
  return a;
};
void inputVector(vector<int>* v) {
  int a;
  while (cin >> a) {
    if (a == -1)break;
    v->push_back(a);
  }
};

void inputVector(vector<int> * p, int a) {
  p->clear();
  p->shrink_to_fit();
  rep(i, a) {
    int input;
    cin >> input;
    p->push_back(input);
  }
}

void inputVector2(vector<vector<int>>& v, ui r, ui c) {
  int temp;
  for (size_t i = 0; i < r; i++)
  {
    for (size_t j = 0; j < c; j++)
    {
      scanf("%d", &temp);
      v[i][j] = temp;
    }
  }
}
void inputVector3(vector<int>* v0, vector<int>* v1) {
  int a;
  unsigned short count = 0b0;
  while (cin >> a) {
    if (a == -1)break;
    if (count)v0->push_back(a); else v1->push_back(a);
    count = count ^ 1;
  }
};

template <typename T>
void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  }
  else {
    cout << a << "\n";
  }
}

template<template <class...> class Map, typename T_0, typename T_1, typename... Args>
void inputMap(Map<T_0, T_1, Args...>& mp) {
  T_0 a;
  T_1 b;
  while (cin >> a && a != -1) {
    cin >> b;
    mp.insert(make_pair(a, b));
  }
}
template<template <class...> class Vec1, template <class...> class Vec2, typename T, typename... Args1, typename... Args2>
void input2dPairVector(Vec1<Vec2<T, Args2...>, Args1...>& vec) {
  T a;
  T b;
  while (cin >> a && a != -1) {
    cin >> b;
    vec.push_back(vector<T>({ a - 1, b - 1 }));
  }
}
template<template <class...> class Vec1, template <class...> class Vec2, typename T, typename... Args1, typename... Args2>
void input2dPairVector(Vec1<Vec2<T, Args2...>, Args1...>& vec, ull size) {
  T a;
  T b;
  for (size_t i = 0; i < size; i++) {
    scanf("%d %d", &a, &b);
    vec.push_back(vector<T>({ a - 1, b - 1 }));
  }
}

template<template <class...> class Vec, typename T, typename U, typename... Args>
void numberToBoolenVector(Vec<T, Args...>& vec, U a) {
  ui i = 0;
  T amari;
  do {
    if (a % (ull)pow(2, i + 1)) {
      amari = 1;
      vec.push_back(amari);
      a -= (ull)pow(2, i);
    }
    else {
      amari = 0;
      vec.push_back(amari);
    }
    i++;
  } while (a);
}

template<template <class...> class Vec, typename T, typename... Args>
ull boolenVectorToNumber(Vec<T, Args...>& vec) {
  ull r = 0;
  for (size_t i = 0; i < vec.size(); i++)
  {
    r += vec[i] * (ull)pow(2, i);
  }
  return r;
}

int main(int argc, const char * argv[]) {
  ll n, m;
  ll lm, rm;
  ll lp, rp;
  bool hani = true;

  scanf("%lld %lld", &n, &m);
  scanf("%lld %lld", &lm, &rm);
  for (size_t i = 1; i < m; i++) {
    scanf("%lld %lld", &lp, &rp);
    if (lm <= lp && lp <= rm) {
      lm = lp;
      if (rp < rm) {
        rm = rp;
      }
    }
    else if (lm <= rp && rp <= rm) {
      rm = rp;
    }
    else if (!(lp <= lm && rm <= rp))
    {
      hani = false;
    }
  }
  if (hani) {
    printf("%d\n", rm - lm + 1);
  }
  else {
    printf("0\n");
  }
}

Measured memory_bytes: 256