import java.util.*;

public class Main {

    private static int N;
    private static int M;
    private static int[] L;
    private static int[] R;

    private static void read() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        L = new int[M]; R = new int[M];
        for (int i = 0; i < M; i += 1) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
    }

    public static void main(String[] args) {
        read();

        int maxL = Integer.MIN_VALUE;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < M; i += 1) {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        }

        if (minR - maxL + 1 >= 0) {
            System.out.println(minR - maxL + 1);
        } else {
            System.out.println(0);
        }
    }
} import java.util.*; util.* java public class Main {

    private static int N;
    private static int M;
    private static int[] L;
    private static int[] R;

    private static void read() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        L = new int[M]; R = new int[M];
        for (int i = 0; i < M; i += 1) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
    }

    public static void main(String[] args) {
        read();

        int maxL = Integer.MIN_VALUE;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < M; i += 1) {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        }

        if (minR - maxL + 1 >= 0) {
            System.out.println(minR - maxL + 1);
        } else {
            System.out.println(0);
        }
    }
} Main private static int N; N private static int M; M private static int[] L; L private static int[] R; R private static void read() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        L = new int[M]; R = new int[M];
        for (int i = 0; i < M; i += 1) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
    } read {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        L = new int[M]; R = new int[M];
        for (int i = 0; i < M; i += 1) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) N = sc.nextInt() N sc.nextInt() sc.nextInt sc M = sc.nextInt() M sc.nextInt() sc.nextInt sc L = new int[M] L new int[M] M R = new int[M] R new int[M] M for (int i = 0; i < M; i += 1) {
            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 += 1 i += 1 i 1 {
            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 public static void main(String[] args) {
        read();

        int maxL = Integer.MIN_VALUE;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < M; i += 1) {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        }

        if (minR - maxL + 1 >= 0) {
            System.out.println(minR - maxL + 1);
        } else {
            System.out.println(0);
        }
    } main {
        read();

        int maxL = Integer.MIN_VALUE;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < M; i += 1) {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        }

        if (minR - maxL + 1 >= 0) {
            System.out.println(minR - maxL + 1);
        } else {
            System.out.println(0);
        }
    } read() read int maxL = Integer.MIN_VALUE; maxL Integer.MIN_VALUE Integer Integer.MIN_VALUE int minR = Integer.MAX_VALUE; minR Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < M; i += 1) {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        } int i = 0; int i = 0; i 0 i < M i M i += 1 i += 1 i 1 {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        } {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        } if (maxL < L[i]) {
                maxL = L[i];
            } maxL < L[i] maxL L[i] L i {
                maxL = L[i];
            } maxL = L[i] maxL L[i] L i if (minR > R[i]) {
                minR = R[i];
            } minR > R[i] minR R[i] R i {
                minR = R[i];
            } minR = R[i] minR R[i] R i if (minR - maxL + 1 >= 0) {
            System.out.println(minR - maxL + 1);
        } else {
            System.out.println(0);
        } minR - maxL + 1 >= 0 minR - maxL + 1 minR - maxL minR maxL 1 0 {
            System.out.println(minR - maxL + 1);
        } System.out.println(minR - maxL + 1) System.out.println System.out System System.out minR - maxL + 1 minR - maxL minR maxL 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 String[] args args public class Main {

    private static int N;
    private static int M;
    private static int[] L;
    private static int[] R;

    private static void read() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        L = new int[M]; R = new int[M];
        for (int i = 0; i < M; i += 1) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
    }

    public static void main(String[] args) {
        read();

        int maxL = Integer.MIN_VALUE;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < M; i += 1) {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        }

        if (minR - maxL + 1 >= 0) {
            System.out.println(minR - maxL + 1);
        } else {
            System.out.println(0);
        }
    }
} public class Main {

    private static int N;
    private static int M;
    private static int[] L;
    private static int[] R;

    private static void read() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        L = new int[M]; R = new int[M];
        for (int i = 0; i < M; i += 1) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
    }

    public static void main(String[] args) {
        read();

        int maxL = Integer.MIN_VALUE;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < M; i += 1) {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        }

        if (minR - maxL + 1 >= 0) {
            System.out.println(minR - maxL + 1);
        } else {
            System.out.println(0);
        }
    }
} Main
import java.util.*;

public class Main {

    private static int N;
    private static int M;
    private static int[] L;
    private static int[] R;

    private static void read() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        L = new int[M]; R = new int[M];
        for (int i = 0; i < M; i += 1) {
            L[i] = Integer.parseInt(sc.next());
            R[i] = Integer.parseInt(sc.next());
        }
    }

    public static void main(String[] args) {
        read();

        int maxL = Integer.MIN_VALUE;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i < M; i += 1) {
            if (maxL < L[i]) {
                maxL = L[i];
            }
            if (minR > R[i]) {
                minR = R[i];
            }
        }

        if (minR - maxL + 1 >= 0) {
            System.out.println(minR - maxL + 1);
        } else {
            System.out.println(0);
        }
    }
}
