import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int Lmax = 0;
        int Rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (Lmax < L[i]) {
                Lmax = L[i];
            }
            if (R[i] < Rmin) {
                Rmin = R[i];
            }
        }
        out.printf("%d\n", Math.max(0, Rmin - Lmax + 1));
        out.flush();
    }
} import java.util.*; util.* java import java.io.*; io.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int Lmax = 0;
        int Rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (Lmax < L[i]) {
                Lmax = L[i];
            }
            if (R[i] < Rmin) {
                Rmin = R[i];
            }
        }
        out.printf("%d\n", Math.max(0, Rmin - Lmax + 1));
        out.flush();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int Lmax = 0;
        int Rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (Lmax < L[i]) {
                Lmax = L[i];
            }
            if (R[i] < Rmin) {
                Rmin = R[i];
            }
        }
        out.printf("%d\n", Math.max(0, Rmin - Lmax + 1));
        out.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int Lmax = 0;
        int Rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (Lmax < L[i]) {
                Lmax = L[i];
            }
            if (R[i] < Rmin) {
                Rmin = R[i];
            }
        }
        out.printf("%d\n", Math.max(0, Rmin - Lmax + 1));
        out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int M = Integer.parseInt(sc.next()); M Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 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] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        } {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        } L[i] = Integer.parseInt(sc.next()) L[i] L i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc R[i] = Integer.parseInt(sc.next()) R[i] R i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int Lmax = 0; Lmax 0 int Rmin = Integer.MAX_VALUE; Rmin Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < M; i++) {
            if (Lmax < L[i]) {
                Lmax = L[i];
            }
            if (R[i] < Rmin) {
                Rmin = R[i];
            }
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            if (Lmax < L[i]) {
                Lmax = L[i];
            }
            if (R[i] < Rmin) {
                Rmin = R[i];
            }
        } {
            if (Lmax < L[i]) {
                Lmax = L[i];
            }
            if (R[i] < Rmin) {
                Rmin = R[i];
            }
        } if (Lmax < L[i]) {
                Lmax = L[i];
            } Lmax < L[i] Lmax L[i] L i {
                Lmax = L[i];
            } Lmax = L[i] Lmax L[i] L i if (R[i] < Rmin) {
                Rmin = R[i];
            } R[i] < Rmin R[i] R i Rmin {
                Rmin = R[i];
            } Rmin = R[i] Rmin R[i] R i out.printf("%d\n", Math.max(0, Rmin - Lmax + 1)) out.printf out "%d\n" Math.max(0, Rmin - Lmax + 1) Math.max Math 0 Rmin - Lmax + 1 Rmin - Lmax Rmin Lmax 1 out.flush() out.flush out String[] args args
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int Lmax = 0;
        int Rmin = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (Lmax < L[i]) {
                Lmax = L[i];
            }
            if (R[i] < Rmin) {
                Rmin = R[i];
            }
        }
        out.printf("%d\n", Math.max(0, Rmin - Lmax + 1));
        out.flush();
    }
}
