#include <bits/stdc++.h>

using namespace std;

int N, M, L, R;

int main(){
    cin >> N >> M;
    L = 1, R = N;
    for(int i = 1; i<=M; i++){
        int l, r;
        cin >> l >> r;
        L = max(l, L), R = min(r, R);
    }
    cout << max(R-L+1, 0) << endl;
}
