#include <bits/stdc++.h>
using namespace std;
 
int arr[100010];
 
int main() {
  int N, M;
  cin >> N >> M;
  int l[M], r[M];
  for (int i = 0; i < M; i++) cin >> l[i] >> r[i];
  
  for (int i = 0; i < M; i++) {
    arr[l[i]]++;
    arr[r[i]+1]--;
  }
  
  for (int i = 1; i < 100010; i++) arr[i] += arr[i-1];
  
  int ans = 0;
  for (int i = 0; i < 100010; i++) if (arr[i] == M) ans++;
  
  cout << ans << endl;
  return 0;
}