import java.util.*;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        }
        scanner.close();

        // index start
        int idxStart = 1;

        // index end
        int idxEnd = N;

        for (int i = 0; i < M; i++) {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        }

        // result count
        int result = idxEnd - idxStart;
        if (result == 0) {
            result = 1;
        } else if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        }

        System.out.println(result);

//        System.out.println(System.currentTimeMillis() - startTime);
    }


}

/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