import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        int max_l = l[0];
        int min_r = r[0];
        for (int i = 1; i < m; i++) {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        }
        if (min_r - max_l < 0) {
            System.out.println(0);
        } else {
            System.out.println(min_r - max_l + 1);
        }
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        int max_l = l[0];
        int min_r = r[0];
        for (int i = 1; i < m; i++) {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        }
        if (min_r - max_l < 0) {
            System.out.println(0);
        } else {
            System.out.println(min_r - max_l + 1);
        }
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        int max_l = l[0];
        int min_r = r[0];
        for (int i = 1; i < m; i++) {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        }
        if (min_r - max_l < 0) {
            System.out.println(0);
        } else {
            System.out.println(min_r - max_l + 1);
        }
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        int max_l = l[0];
        int min_r = r[0];
        for (int i = 1; i < m; i++) {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        }
        if (min_r - max_l < 0) {
            System.out.println(0);
        } else {
            System.out.println(min_r - max_l + 1);
        }
        sc.close();
    } 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 for (int i = 0; i < m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        } 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 int max_l = l[0]; max_l l[0] l 0 int min_r = r[0]; min_r r[0] r 0 for (int i = 1; i < m; i++) {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        } int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        } {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        } max_l = Math.max(max_l, l[i]) max_l Math.max(max_l, l[i]) Math.max Math max_l l[i] l i min_r = Math.min(min_r, r[i]) min_r Math.min(min_r, r[i]) Math.min Math min_r r[i] r i if (min_r - max_l < 0) {
            System.out.println(0);
        } else {
            System.out.println(min_r - max_l + 1);
        } min_r - max_l < 0 min_r - max_l min_r max_l 0 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(min_r - max_l + 1);
        } System.out.println(min_r - max_l + 1) System.out.println System.out System System.out min_r - max_l + 1 min_r - max_l min_r max_l 1 sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        int max_l = l[0];
        int min_r = r[0];
        for (int i = 1; i < m; i++) {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        }
        if (min_r - max_l < 0) {
            System.out.println(0);
        } else {
            System.out.println(min_r - max_l + 1);
        }
        sc.close();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        int max_l = l[0];
        int min_r = r[0];
        for (int i = 1; i < m; i++) {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        }
        if (min_r - max_l < 0) {
            System.out.println(0);
        } else {
            System.out.println(min_r - max_l + 1);
        }
        sc.close();
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        int max_l = l[0];
        int min_r = r[0];
        for (int i = 1; i < m; i++) {
            max_l = Math.max(max_l, l[i]);
            min_r = Math.min(min_r, r[i]);
        }
        if (min_r - max_l < 0) {
            System.out.println(0);
        } else {
            System.out.println(min_r - max_l + 1);
        }
        sc.close();
    }
}