import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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 L = 0;
        int R = n;
        for (int i = 0; i < m; i++) {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        }
        if (L <= R) {
            System.out.println(R - L + 1);
        } else {
            System.out.println(0);
        }

    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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 L = 0;
        int R = n;
        for (int i = 0; i < m; i++) {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        }
        if (L <= R) {
            System.out.println(R - L + 1);
        } else {
            System.out.println(0);
        }

    }

} Main public static void main(String[] args) {
        @SuppressWarnings("resource")
        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 L = 0;
        int R = n;
        for (int i = 0; i < m; i++) {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        }
        if (L <= R) {
            System.out.println(R - L + 1);
        } else {
            System.out.println(0);
        }

    } main {
        @SuppressWarnings("resource")
        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 L = 0;
        int R = n;
        for (int i = 0; i < m; i++) {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        }
        if (L <= R) {
            System.out.println(R - L + 1);
        } else {
            System.out.println(0);
        }

    } @SuppressWarnings("resource")
        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 L = 0; L 0 int R = n; R n for (int i = 0; i < m; i++) {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        } {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        } L = Math.max(L, l[i]) L Math.max(L, l[i]) Math.max Math L l[i] l i R = Math.min(R, r[i]) R Math.min(R, r[i]) Math.min Math R r[i] r i if (L <= R) {
            System.out.println(R - L + 1);
        } else {
            System.out.println(0);
        } L <= R L R {
            System.out.println(R - L + 1);
        } System.out.println(R - L + 1) System.out.println System.out System System.out R - L + 1 R - L R L 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 String[] args args public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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 L = 0;
        int R = n;
        for (int i = 0; i < m; i++) {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        }
        if (L <= R) {
            System.out.println(R - L + 1);
        } else {
            System.out.println(0);
        }

    }

} public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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 L = 0;
        int R = n;
        for (int i = 0; i < m; i++) {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        }
        if (L <= R) {
            System.out.println(R - L + 1);
        } else {
            System.out.println(0);
        }

    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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 L = 0;
        int R = n;
        for (int i = 0; i < m; i++) {
            L = Math.max(L, l[i]);
            R = Math.min(R, r[i]);
        }
        if (L <= R) {
            System.out.println(R - L + 1);
        } else {
            System.out.println(0);
        }

    }

}