#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> a(100010);
	rep(i,m){
		int l,r;cin >> l >> r;
		a.at(l)++;
		a.at(r+1)--;
	}
	rep(i,100001) a.at(i+1)+=a.at(i);
	int ans=0;
	rep(i,100001){
		if(a.at(i)==m) ans++;
	}
	cout << ans << endl;
}
