import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (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();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

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

	public static void main(String[] args) {

		try (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();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

		}
	}
} Main public static void main(String[] args) {

		try (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();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

		}
	} main {

		try (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();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

		}
	} try (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();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

		} {

			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();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) 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 Arrays.sort(l) Arrays.sort Arrays l Arrays.sort(r) Arrays.sort Arrays r if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			} l[m - 1] <= r[0] l[m - 1] l m - 1 m 1 r[0] r 0 {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				} n >= r[0] - l[m - 1] + 1 n r[0] - l[m - 1] + 1 r[0] - l[m - 1] r[0] r 0 l[m - 1] l m - 1 m 1 1 {
					System.out.println(r[0] - l[m - 1] + 1);
				} System.out.println(r[0] - l[m - 1] + 1) System.out.println System.out System System.out r[0] - l[m - 1] + 1 r[0] - l[m - 1] r[0] r 0 l[m - 1] l m - 1 m 1 1 {
					System.out.println(n);
				} System.out.println(n) System.out.println System.out System System.out n {
				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) {

		try (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();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

		}
	}
} public class Main {

	public static void main(String[] args) {

		try (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();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

		}
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (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();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

		}
	}
}
