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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] key = new int[N];
        int[] L = new int[M];
        int[] R = new int[M];

        for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        Arrays.sort(R);
        Arrays.sort(L);

        if (R[0] - L[M - 1] + 1 > 0) {
            System.out.println(R[0] - L[M - 1] + 1);
        } else {
            System.out.println("0");
        }

        sc.close();

    }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] key = new int[N];
        int[] L = new int[M];
        int[] R = new int[M];

        for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        Arrays.sort(R);
        Arrays.sort(L);

        if (R[0] - L[M - 1] + 1 > 0) {
            System.out.println(R[0] - L[M - 1] + 1);
        } else {
            System.out.println("0");
        }

        sc.close();

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

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] key = new int[N];
        int[] L = new int[M];
        int[] R = new int[M];

        for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        Arrays.sort(R);
        Arrays.sort(L);

        if (R[0] - L[M - 1] + 1 > 0) {
            System.out.println(R[0] - L[M - 1] + 1);
        } else {
            System.out.println("0");
        }

        sc.close();

    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] key = new int[N];
        int[] L = new int[M];
        int[] R = new int[M];

        for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        Arrays.sort(R);
        Arrays.sort(L);

        if (R[0] - L[M - 1] + 1 > 0) {
            System.out.println(R[0] - L[M - 1] + 1);
        } else {
            System.out.println("0");
        }

        sc.close();

    } Scanner sc = new Scanner(System.in); sc 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[] key = new int[N]; key new int[N] N int[] L = new int[M]; L new int[M] M int[] R = new int[M]; R new int[M] M for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        } {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        } L[i] = sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc Arrays.sort(R) Arrays.sort Arrays R Arrays.sort(L) Arrays.sort Arrays L if (R[0] - L[M - 1] + 1 > 0) {
            System.out.println(R[0] - L[M - 1] + 1);
        } else {
            System.out.println("0");
        } R[0] - L[M - 1] + 1 > 0 R[0] - L[M - 1] + 1 R[0] - L[M - 1] R[0] R 0 L[M - 1] L M - 1 M 1 1 0 {
            System.out.println(R[0] - L[M - 1] + 1);
        } System.out.println(R[0] - L[M - 1] + 1) System.out.println System.out System System.out R[0] - L[M - 1] + 1 R[0] - L[M - 1] R[0] R 0 L[M - 1] L M - 1 M 1 1 {
            System.out.println("0");
        } System.out.println("0") System.out.println System.out System System.out "0" sc.close() sc.close sc String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] key = new int[N];
        int[] L = new int[M];
        int[] R = new int[M];

        for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        Arrays.sort(R);
        Arrays.sort(L);

        if (R[0] - L[M - 1] + 1 > 0) {
            System.out.println(R[0] - L[M - 1] + 1);
        } else {
            System.out.println("0");
        }

        sc.close();

    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] key = new int[N];
        int[] L = new int[M];
        int[] R = new int[M];

        for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        Arrays.sort(R);
        Arrays.sort(L);

        if (R[0] - L[M - 1] + 1 > 0) {
            System.out.println(R[0] - L[M - 1] + 1);
        } else {
            System.out.println("0");
        }

        sc.close();

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] key = new int[N];
        int[] L = new int[M];
        int[] R = new int[M];

        for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        Arrays.sort(R);
        Arrays.sort(L);

        if (R[0] - L[M - 1] + 1 > 0) {
            System.out.println(R[0] - L[M - 1] + 1);
        } else {
            System.out.println("0");
        }

        sc.close();

    }
}