import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            }

            System.out.println(result);
        }
    }

} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            }

            System.out.println(result);
        }
    }

} Main public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            }

            System.out.println(result);
        }
    } main {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            }

            System.out.println(result);
        }
    } try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            }

            System.out.println(result);
        } {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            }

            System.out.println(result);
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int[] lList = new int[M]; lList new int[M] M int[] rList = new int[M]; rList new int[M] M for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            } {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            } lList[i] = sc.nextInt() lList[i] lList i sc.nextInt() sc.nextInt sc rList[i] = sc.nextInt() rList[i] rList i sc.nextInt() sc.nextInt sc Arrays.sort(lList) Arrays.sort Arrays lList Arrays.sort(rList) Arrays.sort Arrays rList int result = 0; result 0 for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            } int i = lList[lList.length - 1]; int i = lList[lList.length - 1]; i lList[lList.length - 1] lList lList.length - 1 lList.length lList lList.length 1 i <= rList[0] i rList[0] rList 0 i++ i++ i {
                result++;
            } {
                result++;
            } result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            }

            System.out.println(result);
        }
    }

} public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            }

            System.out.println(result);
        }
    }

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int[] lList = new int[M];
            int[] rList = new int[M];
            for (int i = 0; i < M; i++) {
                lList[i] = sc.nextInt();
                rList[i] = sc.nextInt();
            }

            Arrays.sort(lList);
            Arrays.sort(rList);

            int result = 0;

            for (int i = lList[lList.length - 1]; i <= rList[0]; i++) {
                result++;
            }

            System.out.println(result);
        }
    }

}