import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[][] gate = new int[M][2];
        for (int i = 0; i < M; i++) {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        }
        scanner.close();


        // 最小レンジを求める
        int min = Integer.MIN_VALUE;
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        }
        System.out.println(max - min + 1);
    }
}

/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