

import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] L = new int[m];
        int[] R = new int[m];
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        }
        System.out.println(Math.max(minR - maxL + 1, 0));

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

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] L = new int[m];
        int[] R = new int[m];
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        }
        System.out.println(Math.max(minR - maxL + 1, 0));

    }
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] L = new int[m];
        int[] R = new int[m];
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        }
        System.out.println(Math.max(minR - maxL + 1, 0));

    } main {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] L = new int[m];
        int[] R = new int[m];
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        }
        System.out.println(Math.max(minR - maxL + 1, 0));

    } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int[] L = new int[m]; L new int[m] m int[] R = new int[m]; R new int[m] m int maxL = 0; maxL 0 int minR = Integer.MAX_VALUE; minR Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < m; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        } {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        } 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 maxL = Math.max(maxL, L[i]) maxL Math.max(maxL, L[i]) Math.max Math maxL L[i] L i minR = Math.min(minR, R[i]) minR Math.min(minR, R[i]) Math.min Math minR R[i] R i System.out.println(Math.max(minR - maxL + 1, 0)) System.out.println System.out System System.out Math.max(minR - maxL + 1, 0) Math.max Math minR - maxL + 1 minR - maxL minR maxL 1 0 String[] args args public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] L = new int[m];
        int[] R = new int[m];
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        }
        System.out.println(Math.max(minR - maxL + 1, 0));

    }
} public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] L = new int[m];
        int[] R = new int[m];
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        }
        System.out.println(Math.max(minR - maxL + 1, 0));

    }
} Main


import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] L = new int[m];
        int[] R = new int[m];
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            maxL = Math.max(maxL, L[i]);
            minR = Math.min(minR, R[i]);
        }
        System.out.println(Math.max(minR - maxL + 1, 0));

    }
}
