import 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 i, j, tempL, tempR;
        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (i = 0; i < m; i++) {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        }

        if (L > R) {
            System.out.println(0);
            return;
        } else {
            System.out.println(R - L + 1);
        }

        sc.close();

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int i, j, tempL, tempR;
        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (i = 0; i < m; i++) {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        }

        if (L > R) {
            System.out.println(0);
            return;
        } else {
            System.out.println(R - L + 1);
        }

        sc.close();

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int i, j, tempL, tempR;
        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (i = 0; i < m; i++) {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        }

        if (L > R) {
            System.out.println(0);
            return;
        } else {
            System.out.println(R - L + 1);
        }

        sc.close();

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int i, j, tempL, tempR;
        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (i = 0; i < m; i++) {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        }

        if (L > R) {
            System.out.println(0);
            return;
        } else {
            System.out.println(R - L + 1);
        }

        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 i i j j tempL tempL tempR; tempR int L = Integer.MIN_VALUE; L Integer.MIN_VALUE Integer Integer.MIN_VALUE int R = Integer.MAX_VALUE; R Integer.MAX_VALUE Integer Integer.MAX_VALUE for (i = 0; i < m; i++) {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        } i = 0; i = 0 i 0 i < m i m i++ i++ i {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        } {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        } tempL = sc.nextInt() tempL sc.nextInt() sc.nextInt sc tempR = sc.nextInt() tempR sc.nextInt() sc.nextInt sc L = Math.max(L, tempL) L Math.max(L, tempL) Math.max Math L tempL R = Math.min(R, tempR) R Math.min(R, tempR) Math.min Math R tempR if (L > R) {
            System.out.println(0);
            return;
        } else {
            System.out.println(R - L + 1);
        } L > R L R {
            System.out.println(0);
            return;
        } System.out.println(0) System.out.println System.out System System.out 0 return; {
            System.out.println(R - L + 1);
        } System.out.println(R - L + 1) System.out.println System.out System System.out R - L + 1 R - L R L 1 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 i, j, tempL, tempR;
        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (i = 0; i < m; i++) {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        }

        if (L > R) {
            System.out.println(0);
            return;
        } else {
            System.out.println(R - L + 1);
        }

        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 i, j, tempL, tempR;
        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (i = 0; i < m; i++) {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        }

        if (L > R) {
            System.out.println(0);
            return;
        } else {
            System.out.println(R - L + 1);
        }

        sc.close();

    }
} Main
import 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 i, j, tempL, tempR;
        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (i = 0; i < m; i++) {
            tempL = sc.nextInt();
            tempR = sc.nextInt();
            L = Math.max(L, tempL);
            R = Math.min(R, tempR);
        }

        if (L > R) {
            System.out.println(0);
            return;
        } else {
            System.out.println(R - L + 1);
        }

        sc.close();

    }
}
