import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int cardNum = sc.nextInt(); // カード N 枚 ：(0 ~ N-1)
        int gateNum = sc.nextInt(); // ゲート M 個 ：(0 ~ M-1)
        int[] left = new int[gateNum];
        int[] right = new int[gateNum];
        for (int i = 0; i < gateNum; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int curStart = 1;
        int curEnd = cardNum;
        for (int i = 0; i < gateNum; i++) {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        }
        int ans = curEnd - curStart + 1;
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz