import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.OptionalInt;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++) {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            }
            int Lmax = Arrays.stream(L).max().getAsInt();
            int Rmin = Arrays.stream(R).min().getAsInt();
            int ans = Rmin - Lmax + 1;
            out.println(ans < 0 ? 0 : ans);
        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.stream.IntStream; IntStream java.util.stream import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util import java.util.OptionalInt; OptionalInt java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++) {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            }
            int Lmax = Arrays.stream(L).max().getAsInt();
            int Rmin = Arrays.stream(R).min().getAsInt();
            int ans = Rmin - Lmax + 1;
            out.println(ans < 0 ? 0 : ans);
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) C solver = new C(); solver new C() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++) {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            }
            int Lmax = Arrays.stream(L).max().getAsInt();
            int Rmin = Arrays.stream(R).min().getAsInt();
            int ans = Rmin - Lmax + 1;
            out.println(ans < 0 ? 0 : ans);
        }

    } C public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++) {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            }
            int Lmax = Arrays.stream(L).max().getAsInt();
            int Rmin = Arrays.stream(R).min().getAsInt();
            int ans = Rmin - Lmax + 1;
            out.println(ans < 0 ? 0 : ans);
        } solve {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++) {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            }
            int Lmax = Arrays.stream(L).max().getAsInt();
            int Rmin = Arrays.stream(R).min().getAsInt();
            int ans = Rmin - Lmax + 1;
            out.println(ans < 0 ? 0 : ans);
        } int N = in.nextInt(); N in.nextInt() in.nextInt in int M = in.nextInt(); M in.nextInt() in.nextInt in 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] = in.nextInt();
                R[i] = in.nextInt();
            } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            } {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            } L[i] = in.nextInt() L[i] L i in.nextInt() in.nextInt in R[i] = in.nextInt() R[i] R i in.nextInt() in.nextInt in int Lmax = Arrays.stream(L).max().getAsInt(); Lmax Arrays.stream(L).max().getAsInt() Arrays.stream(L).max().getAsInt Arrays.stream(L).max() Arrays.stream(L).max Arrays.stream(L) Arrays.stream Arrays L int Rmin = Arrays.stream(R).min().getAsInt(); Rmin Arrays.stream(R).min().getAsInt() Arrays.stream(R).min().getAsInt Arrays.stream(R).min() Arrays.stream(R).min Arrays.stream(R) Arrays.stream Arrays R int ans = Rmin - Lmax + 1; ans Rmin - Lmax + 1 Rmin - Lmax Rmin Lmax 1 out.println(ans < 0 ? 0 : ans) out.println out ans < 0 ? 0 : ans ans < 0 ans 0 0 ans int testNumber testNumber Scanner in in PrintWriter out out public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++) {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            }
            int Lmax = Arrays.stream(L).max().getAsInt();
            int Rmin = Arrays.stream(R).min().getAsInt();
            int ans = Rmin - Lmax + 1;
            out.println(ans < 0 ? 0 : ans);
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++) {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            }
            int Lmax = Arrays.stream(L).max().getAsInt();
            int Rmin = Arrays.stream(R).min().getAsInt();
            int ans = Rmin - Lmax + 1;
            out.println(ans < 0 ? 0 : ans);
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.OptionalInt;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++) {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            }
            int Lmax = Arrays.stream(L).max().getAsInt();
            int Rmin = Arrays.stream(R).min().getAsInt();
            int ans = Rmin - Lmax + 1;
            out.println(ans < 0 ? 0 : ans);
        }

    }
}

