import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] l = new int[M];
        int[] r = new int[M];

        int lmax = Integer.MIN_VALUE;
        int rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();

            lmax = Math.max(lmax, l[i]);
            rmin = Math.min(rmin, r[i]);
        }

        if (lmax <= rmin) {
            System.out.println(rmin - lmax + 1);
        } else {
            System.out.println(0);
        }

        return;
    }

} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
} Main public static void main(String[] args) {
        new Solver().run();
    } main {
        new Solver().run();
    } new Solver().run() new Solver().run new Solver() String[] args args class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] l = new int[M];
        int[] r = new int[M];

        int lmax = Integer.MIN_VALUE;
        int rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();

            lmax = Math.max(lmax, l[i]);
            rmin = Math.min(rmin, r[i]);
        }

        if (lmax <= rmin) {
            System.out.println(rmin - lmax + 1);
        } else {
            System.out.println(0);
        }

        return;
    }

} Solver public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] l = new int[M];
        int[] r = new int[M];

        int lmax = Integer.MIN_VALUE;
        int rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();

            lmax = Math.max(lmax, l[i]);
            rmin = Math.min(rmin, r[i]);
        }

        if (lmax <= rmin) {
            System.out.println(rmin - lmax + 1);
        } else {
            System.out.println(0);
        }

        return;
    } run {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] l = new int[M];
        int[] r = new int[M];

        int lmax = Integer.MIN_VALUE;
        int rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();

            lmax = Math.max(lmax, l[i]);
            rmin = Math.min(rmin, r[i]);
        }

        if (lmax <= rmin) {
            System.out.println(rmin - lmax + 1);
        } else {
            System.out.println(0);
        }

        return;
    } 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[] l = new int[M]; l new int[M] M int[] r = new int[M]; r new int[M] M int lmax = Integer.MIN_VALUE; lmax Integer.MIN_VALUE Integer Integer.MIN_VALUE int rmin = Integer.MAX_VALUE; rmin Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < M; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();

            lmax = Math.max(lmax, l[i]);
            rmin = Math.min(rmin, 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();

            lmax = Math.max(lmax, l[i]);
            rmin = Math.min(rmin, r[i]);
        } {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();

            lmax = Math.max(lmax, l[i]);
            rmin = Math.min(rmin, 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 lmax = Math.max(lmax, l[i]) lmax Math.max(lmax, l[i]) Math.max Math lmax l[i] l i rmin = Math.min(rmin, r[i]) rmin Math.min(rmin, r[i]) Math.min Math rmin r[i] r i if (lmax <= rmin) {
            System.out.println(rmin - lmax + 1);
        } else {
            System.out.println(0);
        } lmax <= rmin lmax rmin {
            System.out.println(rmin - lmax + 1);
        } System.out.println(rmin - lmax + 1) System.out.println System.out System System.out rmin - lmax + 1 rmin - lmax rmin lmax 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 return;
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] l = new int[M];
        int[] r = new int[M];

        int lmax = Integer.MIN_VALUE;
        int rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();

            lmax = Math.max(lmax, l[i]);
            rmin = Math.min(rmin, r[i]);
        }

        if (lmax <= rmin) {
            System.out.println(rmin - lmax + 1);
        } else {
            System.out.println(0);
        }

        return;
    }

}