import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, sc.nextInt());
            minR = Math.min(minR, sc.nextInt());
        }

        System.out.println(Math.max(0, minR - maxL + 1));
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, sc.nextInt());
            minR = Math.min(minR, sc.nextInt());
        }

        System.out.println(Math.max(0, minR - maxL + 1));
    }
} Main public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, sc.nextInt());
            minR = Math.min(minR, sc.nextInt());
        }

        System.out.println(Math.max(0, minR - maxL + 1));
    } main {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, sc.nextInt());
            minR = Math.min(minR, sc.nextInt());
        }

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

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, sc.nextInt());
            minR = Math.min(minR, sc.nextInt());
        }

        System.out.println(Math.max(0, minR - maxL + 1));
    }
} public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, sc.nextInt());
            minR = Math.min(minR, sc.nextInt());
        }

        System.out.println(Math.max(0, minR - maxL + 1));
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, sc.nextInt());
            minR = Math.min(minR, sc.nextInt());
        }

        System.out.println(Math.max(0, minR - maxL + 1));
    }
}