import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[][] gate = new int[M][2];
        for (int i = 0; i < M; i++) {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        }
        scanner.close();


        // 最小レンジを求める
        int min = Integer.MIN_VALUE;
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        }
        System.out.println(max - min + 1);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[][] gate = new int[M][2];
        for (int i = 0; i < M; i++) {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        }
        scanner.close();


        // 最小レンジを求める
        int min = Integer.MIN_VALUE;
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        }
        System.out.println(max - min + 1);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[][] gate = new int[M][2];
        for (int i = 0; i < M; i++) {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        }
        scanner.close();


        // 最小レンジを求める
        int min = Integer.MIN_VALUE;
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        }
        System.out.println(max - min + 1);
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[][] gate = new int[M][2];
        for (int i = 0; i < M; i++) {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        }
        scanner.close();


        // 最小レンジを求める
        int min = Integer.MIN_VALUE;
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        }
        System.out.println(max - min + 1);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = Integer.parseInt(scanner.next()); N Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int M = Integer.parseInt(scanner.next()); M Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int[][] gate = new int[M][2]; gate new int[M][2] M 2 for (int i = 0; i < M; i++) {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        } {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        } gate[i][0] = Integer.parseInt(scanner.next()) gate[i][0] gate[i] gate i 0 Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner gate[i][1] = Integer.parseInt(scanner.next()) gate[i][1] gate[i] gate i 1 Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner scanner.close() scanner.close scanner int min = Integer.MIN_VALUE; min Integer.MIN_VALUE Integer Integer.MIN_VALUE int max = Integer.MAX_VALUE; max Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < M; i++) {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        } {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        } if (min < gate[i][0]) min = gate[i][0]; min < gate[i][0] min gate[i][0] gate[i] gate i 0 min = gate[i][0] min gate[i][0] gate[i] gate i 0 if (max > gate[i][1]) max = gate[i][1]; max > gate[i][1] max gate[i][1] gate[i] gate i 1 max = gate[i][1] max gate[i][1] gate[i] gate i 1 if (min > max) {
                System.out.println(0);
                return;
            } min > max min max {
                System.out.println(0);
                return;
            } System.out.println(0) System.out.println System.out System System.out 0 return; System.out.println(max - min + 1) System.out.println System.out System System.out max - min + 1 max - min max min 1 String[] args args public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[][] gate = new int[M][2];
        for (int i = 0; i < M; i++) {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        }
        scanner.close();


        // 最小レンジを求める
        int min = Integer.MIN_VALUE;
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        }
        System.out.println(max - min + 1);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[][] gate = new int[M][2];
        for (int i = 0; i < M; i++) {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        }
        scanner.close();


        // 最小レンジを求める
        int min = Integer.MIN_VALUE;
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        }
        System.out.println(max - min + 1);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[][] gate = new int[M][2];
        for (int i = 0; i < M; i++) {
            gate[i][0] = Integer.parseInt(scanner.next());
            gate[i][1] = Integer.parseInt(scanner.next());
        }
        scanner.close();


        // 最小レンジを求める
        int min = Integer.MIN_VALUE;
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            if (min < gate[i][0]) min = gate[i][0];
            if (max > gate[i][1]) max = gate[i][1];

            if (min > max) {
                System.out.println(0);
                return;
            }
        }
        System.out.println(max - min + 1);
    }
}
