#include <bits/stdc++.h>

using namespace std;

int main()
{
  	int n, m;
  	cin >> n >> m;
  	int ll = 1, rr = n;
  	while (m--)
    {
      	int l, r;
      	cin >> l >> r;
      	ll = max(l, ll);
      	rr = min(r, rr);
    }
  	cout << max(0, rr - ll + 1);
  	return 0;
}
